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
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(dxerr
);
50 const CHAR
* descriptionA
;
51 const WCHAR
* descriptionW
;
56 const char * WINAPI
DXGetErrorString9A(HRESULT hr
)
58 unsigned int i
, j
, k
= 0;
59 TRACE("(0x%08x)\n", hr
);
61 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
64 return info
[j
].resultA
;
65 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
74 const WCHAR
* WINAPI
DXGetErrorString9W(HRESULT hr
)
76 static const WCHAR unknown
[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
77 unsigned int i
, j
, k
= 0;
78 TRACE("(0x%08x)\n", hr
);
80 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
83 return info
[j
].resultW
;
84 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
93 const char * WINAPI
DXGetErrorDescription9A(HRESULT hr
)
95 unsigned int i
, j
, k
= 0;
96 TRACE("(0x%08x)\n", hr
);
98 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
100 if (hr
== info
[j
].hr
)
101 return info
[j
].descriptionA
;
102 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
111 const WCHAR
* WINAPI
DXGetErrorDescription9W(HRESULT hr
)
113 static const WCHAR na
[] = { 'n', '/', 'a', 0 };
114 unsigned int i
, j
, k
= 0;
115 TRACE("(0x%08x)\n", hr
);
117 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
119 if (hr
== info
[j
].hr
)
120 return info
[j
].descriptionW
;
121 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
130 HRESULT WINAPI
DXTraceA(const char* strFile
, DWORD dwLine
, HRESULT hr
, const char* strMsg
, BOOL bPopMsgBox
)
133 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile
, dwLine
, hr
, strMsg
, bPopMsgBox
);
136 snprintf(msg
, sizeof(msg
), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
137 strFile
, dwLine
, DXGetErrorString9A(hr
), hr
, strMsg
);
138 MessageBoxA(0, msg
, "Unexpected error encountered", MB_OK
|MB_ICONERROR
);
140 snprintf(msg
, sizeof(msg
), "%s(%d): %s (hr=%s (0x%08x))", strFile
,
141 dwLine
, strMsg
, DXGetErrorString9A(hr
), hr
);
142 OutputDebugStringA(msg
);
148 HRESULT WINAPI
DXTraceW(const char* strFile
, DWORD dwLine
, HRESULT hr
, const WCHAR
* strMsg
, BOOL bPopMsgBox
)
151 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile
, dwLine
, hr
, strMsg
, bPopMsgBox
);
154 static const WCHAR format
[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
155 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
156 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
157 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
158 static const WCHAR caption
[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
159 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
160 /* FIXME: should use wsnprintf */
161 wsprintfW(msg
, format
, strFile
, dwLine
,
162 DXGetErrorString9W(hr
), hr
, strMsg
);
163 MessageBoxW(0, msg
, caption
, MB_OK
|MB_ICONERROR
);
165 static const WCHAR format
[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
166 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
168 /* FIXME: should use wsnprintf */
169 wsprintfW(msg
, format
, strFile
, dwLine
, strMsg
,
170 DXGetErrorString9W(hr
), hr
);
171 OutputDebugStringW(msg
);