Sunday, February 8, 2009

[VC++] Visual Studio Debugger tips for watch window

Displaying GetLastError's value and message in watch window
While debugging it is possible to get the GetLastError() returned after any line of execution and the message associated with it. For viewing the error code and error message in watch window what you need to do is add @err,hr to your watch window and see the value/message displayed on executing program statements.

Displaying pointer as an array in watch window
Suppose you have a pointer array and if you add the same to watch window, by default, you can view only the first value pointed. For viewing all the pointer array content, add the variable name to watch window and add the maximum index to be displayed separated by comma, for eg: watching pnValArr,100 will display all the value of pnValArr from 0 to 100th index. Similarly we can watch intermidate range of a pointer array, for eg: (pnValArr+90),10 will display content of pointer array from index 90 to 100.

See the below debug snapshot showing watch window demonstrating GetLastError() and displaying pointers as array




No comments: