d3dx9: Fix some spec file entries.
[wine.git] / dlls / dxerr9 / dxerr9.c
blobaa1de46b379fc4e14fce34ec1ffafaea0e10942f
1 /*
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
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
29 #include "mmsystem.h"
30 #include "dmerror.h"
31 #include "ddraw.h"
32 #include "dinput.h"
33 #include "vfwmsgs.h"
34 #include "mmstream.h"
35 #include "dplay8.h"
36 #include "dxfile.h"
37 #include "d3d9.h"
38 #include "dsound.h"
40 #include "dxerr9.h"
42 typedef struct {
43 HRESULT hr;
44 const CHAR* resultA;
45 const WCHAR* resultW;
46 const CHAR* descriptionA;
47 const WCHAR* descriptionW;
48 } error_info;
50 #include "errors.h"
52 const char * WINAPI DXGetErrorString9A(HRESULT hr)
54 unsigned int i, j, k = 0;
56 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
57 j = k + (i / 2);
58 if (hr == info[j].hr)
59 return info[j].resultA;
60 if ((unsigned int)hr > (unsigned int)info[j].hr) {
61 k = j + 1;
62 i--;
66 return "Unknown";
69 const WCHAR * WINAPI DXGetErrorString9W(HRESULT hr)
71 static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
72 unsigned int i, j, k = 0;
74 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
75 j = k + (i / 2);
76 if (hr == info[j].hr)
77 return info[j].resultW;
78 if ((unsigned int)hr > (unsigned int)info[j].hr) {
79 k = j + 1;
80 i--;
84 return unknown;
87 const char * WINAPI DXGetErrorDescription9A(HRESULT hr)
89 unsigned int i, j, k = 0;
91 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
92 j = k + (i / 2);
93 if (hr == info[j].hr)
94 return info[j].descriptionA;
95 if ((unsigned int)hr > (unsigned int)info[j].hr) {
96 k = j + 1;
97 i--;
101 return "n/a";
104 const WCHAR * WINAPI DXGetErrorDescription9W(HRESULT hr)
106 static const WCHAR na[] = { 'n', '/', 'a', 0 };
107 unsigned int i, j, k = 0;
109 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
110 j = k + (i / 2);
111 if (hr == info[j].hr)
112 return info[j].descriptionW;
113 if ((unsigned int)hr > (unsigned int)info[j].hr) {
114 k = j + 1;
115 i--;
119 return na;
122 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
124 char msg[1024];
126 if (bPopMsgBox) {
127 wsprintfA(msg, "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
128 strFile, dwLine, DXGetErrorString9A(hr), hr, strMsg);
129 MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
130 } else {
131 wsprintfA(msg, "%s(%d): %s (hr=%s (0x%08x))", strFile,
132 dwLine, strMsg, DXGetErrorString9A(hr), hr);
133 OutputDebugStringA(msg);
136 return hr;
139 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
141 WCHAR msg[1024];
143 if (bPopMsgBox) {
144 static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
145 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
146 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
147 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
148 static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
149 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
150 /* FIXME: should use wsnprintf */
151 wsprintfW(msg, format, strFile, dwLine,
152 DXGetErrorString9W(hr), hr, strMsg);
153 MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
154 } else {
155 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
156 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
157 0 };
158 /* FIXME: should use wsnprintf */
159 wsprintfW(msg, format, strFile, dwLine, strMsg,
160 DXGetErrorString9W(hr), hr);
161 OutputDebugStringW(msg);
164 return hr;