formatmessage

Why is FormatMessage() failing to find a message for WinINet errors?

随声附和 提交于 2019-12-17 16:34:46
问题 I'm running this to test FormatMessage: LPVOID lpMsgBuf; errCode=12163; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , 0, errCode, 0, (LPTSTR) &lpMsgBuf, 0, NULL ); However, when it returns lpMsgBuf contains NULL... I was expecting something like ERROR_INTERNET_DISCONNECTED. Anything look wrong? Thanks. 回答1: That's a WinINet error, and so the message associated with it lives in WinINet.dll. You just need to tell FormatMessage() about this in order for it to

Why does FormatMessage only create partial messages for ERROR_SYSTEM_PROCESS_TERMINATED and ERROR_UNHANDLED_EXCEPTION system errors?

和自甴很熟 提交于 2019-12-05 06:58:23
问题 I have been using the FormatMessage function within the Windows API to generate message strings from system error codes. I noticed that for some error codes the full message doesn't appear to be created. Take this sample program as an example: int main() { wchar_t * buffer = nullptr; FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, ERROR_SYSTEM_PROCESS_TERMINATED, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast

Why does FormatMessage only create partial messages for ERROR_SYSTEM_PROCESS_TERMINATED and ERROR_UNHANDLED_EXCEPTION system errors?

情到浓时终转凉″ 提交于 2019-12-03 22:28:31
I have been using the FormatMessage function within the Windows API to generate message strings from system error codes. I noticed that for some error codes the full message doesn't appear to be created. Take this sample program as an example: int main() { wchar_t * buffer = nullptr; FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, ERROR_SYSTEM_PROCESS_TERMINATED, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&buffer), 0, nullptr); std::wcout << buffer << std::endl; return 0; } According to MSDN I should

Why is FormatMessage() failing to find a message for WinINet errors?

筅森魡賤 提交于 2019-11-27 23:35:43
I'm running this to test FormatMessage : LPVOID lpMsgBuf; errCode=12163; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , 0, errCode, 0, (LPTSTR) &lpMsgBuf, 0, NULL ); However, when it returns lpMsgBuf contains NULL... I was expecting something like ERROR_INTERNET_DISCONNECTED . Anything look wrong? Thanks. Shog9 That's a WinINet error, and so the message associated with it lives in WinINet.dll. You just need to tell FormatMessage() about this in order for it to retrieve the correct message: FormatMessage( // flags: FORMAT_MESSAGE_ALLOCATE_BUFFER // allocate buffer

How should I use FormatMessage() properly in C++?

社会主义新天地 提交于 2019-11-26 21:34:30
Without : MFC ATL How can I use FormatMessage() to get the error text for a HRESULT ? HRESULT hresult = application.CreateInstance("Excel.Application"); if (FAILED(hresult)) { // what should i put here to obtain a human-readable // description of the error? exit (hresult); } Shog9 Here's the proper way to get an error message back from the system for an HRESULT (named hresult in this case, or you can replace it with GetLastError() ): LPTSTR errorText = NULL; FormatMessage( // use system message tables to retrieve error text FORMAT_MESSAGE_FROM_SYSTEM // allocate buffer on local heap for error

How should I use FormatMessage() properly in C++?

戏子无情 提交于 2019-11-26 08:01:41
问题 Without : MFC ATL How can I use FormatMessage() to get the error text for a HRESULT ? HRESULT hresult = application.CreateInstance(\"Excel.Application\"); if (FAILED(hresult)) { // what should i put here to obtain a human-readable // description of the error? exit (hresult); } 回答1: Here's the proper way to get an error message back from the system for an HRESULT (named hresult in this case, or you can replace it with GetLastError() ): LPTSTR errorText = NULL; FormatMessage( // use system