Sign in to follow this  

Message tables in DirectX Libs?

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

I'm working on resource editor for future DirectX work and wish to give it robust error checking. Can I use FormatMessage to obtain a description of DirectX return codes like I can with Windows? Here's one of my error tracking objects and its reporting function.
[SOURCE]namespace D3D
{
	class Status_C : private ::Status_C
	{
		friend class Renderer_C;
		friend class Subview_C;
	public:
		Status_C() { Code.DirectX = 0; }
		~Status_C() { Code.DirectX = 0; }

		bool Is_Good() const;
		unsigned long Report(TCHAR *Buffer, const unsigned long Buffer_Len) const;

	private:
		union Code_U {
			Code_T This;
			DWORD Windows;
			HRESULT DirectX;
		} Code;
	};

unsigned long Status_C::Report(TCHAR *Buffer, const unsigned long Buffer_Len) const
	{
		TCHAR *Buf_Cursor = Buffer;
		unsigned long Seg_Len = 0, Buf_Remain = Buffer_Len;

		switch (API)
		{
		case This:
			Seg_Len = _sntprintf(Buf_Cursor, Buf_Remain, TEXT("I encountered error #%hu."), Code.This);
			Buf_Remain -= Seg_Len, Buf_Cursor += Seg_Len;
			break;

		case Windows:
			Seg_Len = _sntprintf(Buf_Cursor, Buf_Remain, TEXT("Windows said, \""));
			Buf_Remain -= Seg_Len, Buf_Cursor += Seg_Len;

			Seg_Len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL, Code.Windows, 0, Buf_Cursor, Buf_Remain, NULL);
			Buf_Remain -= Seg_Len, Buf_Cursor += Seg_Len;

			Seg_Len = _sntprintf(Buf_Cursor, Buf_Remain, TEXT("\""));
			Buf_Remain -= Seg_Len, Buf_Cursor += Seg_Len;
			break;

//Can FormatMessage be used in this case?
		case DirectX:
			Seg_Len = _sntprintf(Buffer, Buffer_Len, TEXT("Direct3D returned code #%X."), Code.DirectX);
			Buf_Remain -= Seg_Len, Buf_Cursor += Seg_Len;
			break;
		}
		return Buffer_Len - Buf_Remain;
	}[/SOURCE]
Thanks folks. :) [Edited by - Chris_19741005 on January 6, 2008 1:02:22 PM]

Share this post


Link to post
Share on other sites
Not that I'm aware of. You can however use DXGetErrorDescription to return a string containing a description of the error, and DXGetErrorString to return the name of the error; e.g. "D3DERR_OUTOFVIDEOMEMORY".

In fact, the docs say that those functions support Win32 error codes too, so you might be able to avoid using FormatMessage() at all.

Share this post


Link to post
Share on other sites

This topic is 3627 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this