I want to retrieve error strings for DirectX 9, but I can find on the web is using the FormatMessage() and _com_error.ErrorMessage(), both of which fail me.
hr = g_pd3dDevice->GetRenderTargetData(...
... // the debugger tells me hr = 0x8876086c
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, hr, 0, (LPTSTR)&lpBuf, 0, NULL))
// it returns 0 with lpBuf unallocated
FormatMessage() fails and I use the it again with GetLastError() to see why FormatMessage() fails:
“The system cannot find message text for message number 0x%1 in the message file for %2.”
_com_error.ErrorMessage() tells me “Unknown error 0x8876086c”
To get DirectX error message, there are two functions —
DXGetErrorString()andDXGetErrorDescription(). That being said,FormatMessage()will not get you what you want. Here is a small example:…