2 * DirectX 9 error routines
4 * Copyright 2004 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
51 const CHAR* descriptionA;
52 const WCHAR* descriptionW;
57 const char * WINAPI DXGetErrorString9A(HRESULT hr)
59 unsigned int i, j, k = 0;
60 TRACE("(0x%08x)\n", hr);
62 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
65 return info[j].resultA;
66 if ((unsigned int)hr > (unsigned int)info[j].hr) {
75 const WCHAR * WINAPI DXGetErrorString9W(HRESULT hr)
77 static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
78 unsigned int i, j, k = 0;
79 TRACE("(0x%08x)\n", hr);
81 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
84 return info[j].resultW;
85 if ((unsigned int)hr > (unsigned int)info[j].hr) {
94 const char * WINAPI DXGetErrorDescription9A(HRESULT hr)
96 unsigned int i, j, k = 0;
97 TRACE("(0x%08x)\n", hr);
99 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
101 if (hr == info[j].hr)
102 return info[j].descriptionA;
103 if ((unsigned int)hr > (unsigned int)info[j].hr) {
112 const WCHAR * WINAPI DXGetErrorDescription9W(HRESULT hr)
114 static const WCHAR na[] = { 'n', '/', 'a', 0 };
115 unsigned int i, j, k = 0;
116 TRACE("(0x%08x)\n", hr);
118 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
120 if (hr == info[j].hr)
121 return info[j].descriptionW;
122 if ((unsigned int)hr > (unsigned int)info[j].hr) {
131 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
134 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
137 snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
138 strFile, dwLine, DXGetErrorString9A(hr), hr, strMsg);
139 MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
141 snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
142 dwLine, strMsg, DXGetErrorString9A(hr), hr);
143 OutputDebugStringA(msg);
149 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
152 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
155 static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
156 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
157 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
158 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
159 static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
160 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
161 /* FIXME: should use wsnprintf */
162 wsprintfW(msg, format, strFile, dwLine,
163 DXGetErrorString9W(hr), hr, strMsg);
164 MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
166 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
167 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
169 /* FIXME: should use wsnprintf */
170 wsprintfW(msg, format, strFile, dwLine, strMsg,
171 DXGetErrorString9W(hr), hr);
172 OutputDebugStringW(msg);