Archived

This topic is now archived and is closed to further replies.

cnstrnd

Looking for HRESULT 2 String convertor source code

Recommended Posts

As mentionned, I am looking for a function that takes an HRESULT as parameter and returns a string. Something like a huge switch/case for use with DDraw. I once found one on the internet but can''t remember where. Thanks for your help

Share this post


Link to post
Share on other sites
Something like this perhaps? It is using MFC CString though, but you could surely convert it to std::string.

  
CString GetErrorMessage(HRESULT hResult)
{
CString strMessage;
char* szMessage = NULL;
if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<char*>(&szMessage), 0, NULL) && (szMessage != NULL))
{
strMessage = szMessage;
strMessage.Trim();
::LocalFree(reinterpret_cast<HLOCAL>(szMessage));
}
else
{
strMessage.Format("Unknown error 0x%08lX", hResult);
}

return strMessage;
}




Update GameDev.net system time campaign - success at last

Share this post


Link to post
Share on other sites
Thanks a lot but I already use FormatMessage to GetLastError codes. Unfortunately it doesn't work with DirectX (at least with DirectDraw).

Something else ?

[edited by - cnstrnd on March 5, 2003 11:00:41 AM]

Share this post


Link to post
Share on other sites
Thanks pipo but I currently use DD only.

(in) Any HRESULT return code from Direct3D®, DirectPlay®, DirectMusic®, DirectSound®, DirectInput®, and DirectShow®.

I don''t really understand why this function doesn''t support DDraw thought.

And bmorberly, you''re my prophet of the day !!
Many thanks for this link !

Share this post


Link to post
Share on other sites