There is no error string provided by DirectDraw. You have to look at the returned HRESULT and format your own string as needed. For example:
How to get DirectDraw Last error string(DirectX 7)
-
26-06-2022 - |
Domanda
When I failed executing a DirectDraw method, how to get the failure error string in DirectX 7?
if (FAILED(lpddPrimarySurface->SetPalette(lpddPalette)))
{
MessageBox(NULL, **"I want to get the failure string here."**, "Error", MB_OK);
return 0;
}
Here I want to pop up the error messge of the failure information. How to get the LPCSTR string of the error?
Soluzione 2
Altri suggerimenti
For NTSTATUS errors the following is possible. Not sure if this will work for Direct Draw and Direct X HRESULT error codes, but it may do as they may be in the system message table. You don't need the ntdll handle either I don't think because the look up is done on the system message table. I have specified it just in case as I have never tested without it.
Excuse the static char array, this just to show example, not a good implementation :)
static const char *NTStatusToString(DWORD NtStatusCode)
{
LPVOID lpMessageBuffer = 0;
HMODULE hNTDll = GetModuleHandle("ntdll.dll");
static char szBuffer[256];
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_FROM_HMODULE,
hNTDll,
NtStatusCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMessageBuffer,
0,
NULL);
memset(szBuffer, 0, sizeof(szBuffer));
_snprintf(szBuffer, sizeof(szBuffer)-1, "%s", lpMessageBuffer);
LocalFree(lpMessageBuffer);
return szBuffer;
}
This thread suggests it will work How should I use FormatMessage() properly in C++? however this one suggests it won't Is there a way to get the string representation of HRESULT value using win API? and you will have to do a bit more work than this.