Jump to content
  • Advertisement

Archived

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

FrigidHelix

Converting HRESULT to string

This topic is 6458 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

While debugging, I am able to view the value of the HRESULT returned by directX functions. However, I am unable to make sense out of this, as the documentation (from what I found), only gives the define of the error code, and not its actual value. Is there anyplace where the values are listed, so I can see what the error is, or is there a function to convert it to a string. I remember having seen a function which did this, i just dont remember where it was.

Share this post


Link to post
Share on other sites
Advertisement
Hi!

Try the following, cut from the MSDN on FormatMessage

LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );


also, you know that if you have a HRESULT in the watch window in the debugger, you can add a ,hr to make the debugger write the string description..

Cheers,
Magnus

Share this post


Link to post
Share on other sites
And if that doesnt work, it''s pretty simple to make a function that will return a string for the error.

The error values and their meanings are in the DirectX docs. You can cut and paste all that into VC, then use a VC quick-macro to convert all the text into source code, like..

switch(ret)
{ case DDERR_xxxx: return "blah";
...
default: return "Unknown error.";

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!