[MFC] Cum vizualizez continutul containerelor MFC?

Despre MFC, ATL si alte biblioteci C++ de la Microsoft (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[MFC] Cum vizualizez continutul containerelor MFC?

Post by Ovidiu Cucu » 25 Apr 2013, 19:19

Q: Visual Studio afiseaza in fereastra Watch, elementele unui container STL.
Exemplu:
Watch STL vector.jpg
Watch STL vector.jpg (41.07 KiB) Viewed 6851 times
In schimb daca, punem in fereasta Watch un obiect de tip container (collection) MFC, de exemplu CStringArray vom vedea geva de genul.
Watch CStringArray.jpg
Watch CStringArray.jpg (37.81 KiB) Viewed 6851 times
Cum am putea sa vizualizam elementele unui container tip CStringArray sau a altor tipuri de containere MFC (CArray, CPtrArray, CObArray, etc) la fel ca si in cazul celor STL?

A: O solutie imediata ar fi de a pune manual in watch, element cu element.
De exemplu, arr.m_pData[0], arr.m_pData[1], s.a.m.d.
Watch CStringArray elements.jpg
Watch CStringArray elements.jpg (38.13 KiB) Viewed 6851 times
Este destul de "peste mana" pentru ca ar trebui sa facem asta oridecate ori este nevoie.

O solutie mai eleganta este editarea fisierului autoexp.dat care se gaseste acolo unde este instalat Visual Studio, in subfolderul \Common7\Packages\Debugger.
Deci, facem mai intai o copie "de siguranta" apoi deschidem autoexp.dat cu un editor de text si adaugam urmatoarele sub sectiunea [Visualizer].

Code: Select all

;---------------------------------------------------------------------
; MFC Arrays
;---------------------------------------------------------------------
CArray<*,*>|CObArray|CByteArray|CDWordArray|CPtrArray|CStringArray|CWordArray|CUIntArray|CTypedPtrArray<*,*>{
  preview([$c,!])
	children(
				#(
					#array (
						expr: $c.m_pData[$i],
						size: $c.m_nSize
							),
					#(raw : [$c,!])
				)
			)
}
De-acum inainte, pentru array-urile MFC, fereastra Watch va afisa element cu element.
In exemplul nostru, un CStringArray va arata asa:
Watch CStringArray (using modified autoexp file).jpg
Watch CStringArray (using modified autoexp file).jpg (41.35 KiB) Viewed 6851 times
Similar se poate proceda si pentru containerele MFC tip list si map.

Code: Select all

;---------------------------------------------------------------------
; MFC Lists
;---------------------------------------------------------------------
CList<*,*>|CObList|CPtrList|CStringList|CTypedPtrList<*,*>{
  preview([$c,!])
    children(
        #(
			#list	(
				head: $c.m_pNodeHead,
				next: pNext
					) : $e.data,
			#(raw : [$c,!])
		)
	)
}

Code: Select all

;---------------------------------------------------------------------
; MFC Maps
;---------------------------------------------------------------------
CMap<*,*,*,*>::CAssoc{
preview(#("key= ",$e.key,", value= ", $e.value))
}

CMap<*,*,*,*>|CMapPtrToWord|CMapPtrToPtr|CMapStringToOb|CMapStringToPtr|CMapStringToString|CMapWordToOb|CMapWordToPtr|CTypedPtrMap<*,*,*>{
    children (
        #(
            #array (
                expr : ($c.m_pHashTable)[$i],
                size : $c.m_nHashTableSize
            ) : #(
                #list (
                    head : $e,
                    next : pNext
					)
				)
        )
    )
}
Vezi si
<< Back to MFC index



Post Reply