Skip to main content
gamedev.net
🔒 Locked

DPlay error codes (C++)

Started by m_shuhrat Apr 13, 2007 at 3:20 PM 3 replies 800+ views
Original Post
m_shuhrat
m_shuhrat
Good evening all, I wondered if I could cast error codes returned when calling functions, say for instance if I want to test result code and show it to myself in easier format, like in messagebox (really for debuggin purposes): HRESULT hr=dPlay->Open(&sDes,DPOPEN_JOIN); Is there easied way to check return code, rather than nesting in switch block to test for every single return value. and another question is, even though I create and run both lobby server, and client on the same computer, it takes considerably long time for client to locate a session. is it nature of it, or is there something wrong in my code, it takes about nearly 20 secs to get respond from session enumerator. Thanks in advance.
ext
ext
Yes there is a way. You can test a HRESULT with the FAILED() macro and the SUCCEEDED() macro.

And if you want to print the error code, you can use DXGetErrorString and DXGetErrorDescription both are declared in dxerr.h (but iirc you have to use the dxerr9.h for dx9).
m_shuhrat
m_shuhrat
what if I'm using DPlay version 4?
Evil Steve
Evil Steve
DXGetErrorString and DXGetErrorDescription don't handle DirectPlay errors according to the docs.

If the error is a standard windows error message, you can use FormatMessage() to convert it to a string, otherwise, the only real way is a large switch statement. But you'll only need to write the code once in a function, and then you can call it from wherever you like, and there can't be that many error codes, surely.

If you want to give FormatMessage() a go, try this out:
std::string FormatWindowsError(int nError){char* szMsgBuffer;	FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,		NULL, nError, 0, (LPTSTR)&szMsgBuffer, 0, NULL);	std::string strRet(szMsgBuffer);	LocalFree(szMsgBuffer);	return strRet;}
Assuming you're using MBCS not unicode.
m_shuhrat
m_shuhrat
Quote:
Original post by Evil Steve
the only real way is a large switch statement. ...


I think that what it is going to be. Cos I need DirectPlay error code. Thought there might be some easier way, but nevermind.




Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.