In this sample,the dwerror is 10045L
.but this code returns 0x13d value as error.
How to get the format message?Please have a look into it.
TCHAR lpMsgBuf[512];
if(!FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL ))
{
wprintf(L"Format message failed with 0x%x\n", GetLastError());
return;
}
0x13d == 317 ==
ERROR_MR_MID_NOT_FOUND
. The message for the error you're trying to find doesn't exist in SYSTEM. Maybe your error originate from a specific dll or driver. If you know which dll\driver try to abtain it handle and specifyFORMAT_MESSAGE_FROM_HMODULE
instead ofFORMAT_MESSAGE_FROM_SYSTEM
and supply the handle as the source in the call toFormatMessage
.And besides that if you use
FORMAT_MESSAGE_ALLOCATE_BUFFER
you should declare a variable of typeLPTSTR
likeLPTSTR pMsg;
and pass it to FormatMessage as(LPTSTR)&pMsg
and when you're done with it useLocalFree(pMsg)
to release the allocated memory.