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.
Further reading: here and here and here