Jump to content
  • Advertisement
Sign in to follow this  
grill8

Quick question about DXGetErrorString/Description and Win32.

This topic is 3567 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

Hello, I am proficient with DirectX but am somewhat new to Win32. I know that the functions DXGetErrorString and DXGetErrorDescription work with Win32 but I would like to have separate Win32 error handling support not reliant on DirectX. Question) Are there Win32 versions of DirectX functions DXGetErrorString and DXGetErrorDescription? If not, how do I handle get error information in Win32 when not using DirectX? Thank you for your help. Jeremy

Share this post


Link to post
Share on other sites
Advertisement
FormatMessage. From my code:

std::wstring Util::Win32ErrorToString(DWORD dwErrorCode)
{
wchar_t* szMsgBuffer;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, 0, (LPTSTR)&szMsgBuffer, 0, NULL);
std::wstring strRet(szMsgBuffer);
LocalFree(szMsgBuffer);
return strRet;
}

Share this post


Link to post
Share on other sites
Thank you both for your help.

Evil Steve -
I got the sample function to work but only if I changed it from wstring to string. Otherwise it was just outputing garbage. I have never used a wstring before so I'll do some research into it. If you have any additional information I would love to hear it.
Just an idea, but you might want to pass the output error string by reference so you can dodge the copy constructor call on return.

So ... I guess the sample function works as far as a Win32 version of DXGetErrorDescription, but is there a function that converts the error code to its equivalent text value i.e. "ERROR_RESOURCE_LANG_NOT_FOUND" like DXGetErrorString does?

Thank you both for your help.
Jeremy

Share this post


Link to post
Share on other sites
std::wstring is like std::string, except it uses wchar_t (16-bit) instead of char (8-bit). The Windows API will use strings of wchar_t to represent Unicode strings, and in general you'll want to use Unicode since these days there's almost no reason not to.

If you want to read up a bit on how Unicode works in the Windows API, you can read this blog entry.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
std::wstring is like std::string, except it uses wchar_t (16-bit) instead of char (8-bit).

To be pedantic, wchar_t isn't always 16 bits. It is on Windows, but on most other platforms, wchar_t is a 32 bit type.

Share this post


Link to post
Share on other sites
Thank you both -

MJP -
That was a fantastic explanation, I have been needing that information for quite a while, so thank you.

All -
If anyone knows of/has a way to implement a Win32 version of DXGetErrorString I would greatly appreciate it. The DXGetErrorDescription seems to be covered in the sample code above, but DXGetErrorString is not.

Thank you for your help.
Jeremy

Share this post


Link to post
Share on other sites
Sorry, I don't of any way to get the actual name of a Win32 error code.

Share this post


Link to post
Share on other sites
I'm also not aware of any way of getting the error code. However, is it really that useful? If it's to log the error for reporting, just log the error number.

Personally, I don't think I've ever used DXGetErrorString, I always use DXGetErrorDescription.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!