How can I get error lines for DirectX 9

I want to get error strings for DirectX 9, but I can search the Internet using FormatMessage () and _com_error.ErrorMessage (), both of which do not work.

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 () error, and I use it again with GetLastError () to find out why FormatMessage () crashes: "The system cannot find the message text for message number 0x% 1 in the message file for% 2".

_com_error.ErrorMessage () tells me "Unknown error 0x8876086c"

+9
source share
2 answers

To get a DirectX error message, there are two functions - DXGetErrorString() and DXGetErrorDescription() . However, FormatMessage() will not get you what you want. Here is a small example:

 // You'll need this include file and library linked. #include <DxErr.h> #pragma comment(lib, "dxerr.lib") 

...

 if (FAILED(hr)) { fprintf(stderr, "Error: %s error description: %s\n", DXGetErrorString(hr), DXGetErrorDescription(hr)); } 
+17
source

According to https://walbourn.imtqy.com/wheres-dxerr-lib/ (also related to kreuzerkrieg comment):

HRESULTS for DirectX graphics APIs were added to the FormatMessage function when using FORMAT_MESSAGE_FROM_SYSTEM in Windows 8, which already supports most of the system error codes reported by DXERR

At the same time, the previous DXERR.LIB library containing the DXGetErrorString() function was deleted in the Windows SDK 8 (which included the DirectX SDK).

If you need a solution that works on any Windows OS, you can use the “simplified version” of the DXERR.LIB library with the MIT license hosted on this website.

0
source

All Articles