Page 1 of 1

[MFC] Cum vizualizez continutul containerelor MFC?

Posted: 25 Apr 2013, 19:19
by Ovidiu Cucu
Q: Visual Studio afiseaza in fereastra Watch, elementele unui container STL.
Exemplu:
Watch STL vector.jpg
Watch STL vector.jpg (41.07 KiB) Viewed 8450 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 8450 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 8450 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 8450 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