Free Source Code and Program Tips
Microsoft Visual C++ Tips
Here are some tips of Microsoft Visual Studio 6.0.
Display the LastError’s value
When we want to get the LastError message, we often using the following code.
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// …
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, “Error”, MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
But now VisualSudio 6.0 has provied a virtual Pseudoregister called
we can simply input the expression in the watch window and we will get the LastError message.
@ERR
;Last error value,the same value returned by the GetLastError() API function
@TIB
;Thread information block for the current thread
@CLK
;Undocumented clock register; usable only in the Watch window
@EAX, @EBX, @ECX, @EDX, @ESI, @EDI, @EIP, @ESP, @EBP, @EFL
;Intel CPU registers
@CS, @DS, @ES, @SS, @FS, @GS
;Intel CPU segment registers
@ST0, @ST1, @ST2, @ST3, @ST4, @ST5, @ST6, @ST7
;Intel CPU floating-point registers
Acknowledge:
[1]An introduction to debugging in MSVC++ using Pseudoregisters
[2]Microsoft Visual C++ Tips and Tricks
| Print article | This entry was posted by hamo on November 21, 2006 at 10:12 pm, and is filed under Win32/MFC. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |