|
-
June 12th, 2009, 03:02 AM
#1
GetLastError() in a MessageBox()?
Hi,
can you tell me how to display the GetLastError() in a MessageBox()?
Thanks!
-
June 12th, 2009, 04:23 AM
#2
Re: GetLastError() in a MessageBox()?
Use FormatMessage() function to get error code string...
Thanks,
-
June 12th, 2009, 04:32 AM
#3
Re: GetLastError() in a MessageBox()?
-
June 12th, 2009, 01:50 PM
#4
Re: GetLastError() in a MessageBox()?
GetLastError() return the calling thread's last-error code.
Error codes are 32-bit values so to display the error code you will have to construct a string representation of the error code, something like:
Code:
std::ostringstream ss;
DWORD dwLastError = ::GetLastError();
ss << dwLastError ;
YourMessageBox( ss.str(), ss.str().c_str() );
As indicated, You can obtain error message strings for system error codes using FormatMessage(), something like:
Code:
int main()
{
void* lpBuffer;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
::GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpBuffer,
0,
NULL );
MessageBox( NULL, (LPCTSTR)lpBuffer, __T("LastRrror"), MB_OK );
LocalFree( lpBuffer );
return 0;
}
Regards
Doron Moraz
Last edited by Doron Moraz; June 12th, 2009 at 01:56 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|