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
24 #define COM_NO_WINDOWS_H
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(dxerr
);
52 const CHAR
* descriptionA
;
53 const WCHAR
* descriptionW
;
58 const char * WINAPI
DXGetErrorString9A(HRESULT hr
)
60 unsigned int i
, j
, k
= 0;
61 TRACE("(0x%08lx)\n", hr
);
63 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
66 return info
[j
].resultA
;
67 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
76 const WCHAR
* WINAPI
DXGetErrorString9W(HRESULT hr
)
78 static const WCHAR unknown
[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
79 unsigned int i
, j
, k
= 0;
80 TRACE("(0x%08lx)\n", hr
);
82 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
85 return info
[j
].resultW
;
86 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
95 const char * WINAPI
DXGetErrorDescription9A(HRESULT hr
)
97 unsigned int i
, j
, k
= 0;
98 TRACE("(0x%08lx)\n", hr
);
100 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
102 if (hr
== info
[j
].hr
)
103 return info
[j
].descriptionA
;
104 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
113 const WCHAR
* WINAPI
DXGetErrorDescription9W(HRESULT hr
)
115 static const WCHAR na
[] = { 'n', '/', 'a', 0 };
116 unsigned int i
, j
, k
= 0;
117 TRACE("(0x%08lx)\n", hr
);
119 for (i
= sizeof(info
)/sizeof(info
[0]); i
!= 0; i
/= 2) {
121 if (hr
== info
[j
].hr
)
122 return info
[j
].descriptionW
;
123 if ((unsigned int)hr
> (unsigned int)info
[j
].hr
) {
132 HRESULT WINAPI
DXTraceA(const char* strFile
, DWORD dwLine
, HRESULT hr
, const char* strMsg
, BOOL bPopMsgBox
)
135 TRACE("(%p,%ld,0x%08lx,%p,%d)\n", strFile
, dwLine
, hr
, strMsg
, bPopMsgBox
);
138 snprintf(msg
, sizeof(msg
), "File: %s\nLine: %ld\nError Code: %s (0x%08lx)\nCalling: %s",
139 strFile
, dwLine
, DXGetErrorString9A(hr
), hr
, strMsg
);
140 MessageBoxA(0, msg
, "Unexpected error encountered", MB_OK
|MB_ICONERROR
);
142 snprintf(msg
, sizeof(msg
), "%s(%ld): %s (hr=%s (0x%08lx))", strFile
,
143 dwLine
, strMsg
, DXGetErrorString9A(hr
), hr
);
144 OutputDebugStringA(msg
);
150 HRESULT WINAPI
DXTraceW(const char* strFile
, DWORD dwLine
, HRESULT hr
, const WCHAR
* strMsg
, BOOL bPopMsgBox
)
153 TRACE("(%p,%ld,0x%08lx,%p,%d)\n", strFile
, dwLine
, hr
, strMsg
, bPopMsgBox
);
156 static const WCHAR format
[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
157 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
158 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
159 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
160 static const WCHAR caption
[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
161 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
162 /* FIXME: should use wsnprintf */
163 wsprintfW(msg
, format
, strFile
, dwLine
,
164 DXGetErrorString9W(hr
), hr
, strMsg
);
165 MessageBoxW(0, msg
, caption
, MB_OK
|MB_ICONERROR
);
167 static const WCHAR format
[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
168 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
170 /* FIXME: should use wsnprintf */
171 wsprintfW(msg
, format
, strFile
, dwLine
, strMsg
,
172 DXGetErrorString9W(hr
), hr
);
173 OutputDebugStringW(msg
);