Don't include windows.h & co in the Wine sources.
[wine/gsoc_dplay.git] / dlls / dxerr8 / dxerr8.c
blob9a0160dd9aaf523f815c9fd72d3d37617b0c6d6b
1 /*
2 * DirectX 8 error routines
4 * Copyright 2004-2005 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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
30 #include "mmsystem.h"
31 #include "dsound.h"
32 #include "dmerror.h"
33 #include "ddraw.h"
34 #include "dinput.h"
35 #include "vfwmsgs.h"
37 #include "dxerr8.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
43 typedef struct {
44 HRESULT hr;
45 const CHAR* resultA;
46 const WCHAR* resultW;
47 const CHAR* descriptionA;
48 const WCHAR* descriptionW;
49 } error_info;
51 #include "errors.h"
53 const char * WINAPI DXGetErrorString8A(HRESULT hr)
55 unsigned int i, j, k = 0;
56 TRACE("(0x%08x)\n", hr);
58 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
59 j = k + (i / 2);
60 if (hr == info[j].hr)
61 return info[j].resultA;
62 if ((unsigned int)hr > (unsigned int)info[j].hr) {
63 k = j + 1;
64 i--;
68 return "Unknown";
71 const WCHAR * WINAPI DXGetErrorString8W(HRESULT hr)
73 static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
74 unsigned int i, j, k = 0;
75 TRACE("(0x%08x)\n", hr);
77 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
78 j = k + (i / 2);
79 if (hr == info[j].hr)
80 return info[j].resultW;
81 if ((unsigned int)hr > (unsigned int)info[j].hr) {
82 k = j + 1;
83 i--;
87 return unknown;
90 const char * WINAPI DXGetErrorDescription8A(HRESULT hr)
92 unsigned int i, j, k = 0;
93 TRACE("(0x%08x)\n", hr);
95 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
96 j = k + (i / 2);
97 if (hr == info[j].hr)
98 return info[j].descriptionA;
99 if ((unsigned int)hr > (unsigned int)info[j].hr) {
100 k = j + 1;
101 i--;
105 return "n/a";
108 const WCHAR * WINAPI DXGetErrorDescription8W(HRESULT hr)
110 static const WCHAR na[] = { 'n', '/', 'a', 0 };
111 unsigned int i, j, k = 0;
112 TRACE("(0x%08x)\n", hr);
114 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
115 j = k + (i / 2);
116 if (hr == info[j].hr)
117 return info[j].descriptionW;
118 if ((unsigned int)hr > (unsigned int)info[j].hr) {
119 k = j + 1;
120 i--;
124 return na;
127 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
129 char msg[1024];
130 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
132 if (bPopMsgBox) {
133 snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
134 strFile, dwLine, DXGetErrorString8A(hr), hr, strMsg);
135 MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
136 } else {
137 snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
138 dwLine, strMsg, DXGetErrorString8A(hr), hr);
139 OutputDebugStringA(msg);
142 return hr;
145 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
147 WCHAR msg[1024];
148 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
150 if (bPopMsgBox) {
151 static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
152 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
153 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
154 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
155 static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
156 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
157 /* FIXME: should use wsnprintf */
158 wsprintfW(msg, format, strFile, dwLine,
159 DXGetErrorString8W(hr), hr, strMsg);
160 MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
161 } else {
162 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
163 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
164 0 };
165 /* FIXME: should use wsnprintf */
166 wsprintfW(msg, format, strFile, dwLine, strMsg,
167 DXGetErrorString8W(hr), hr);
168 OutputDebugStringW(msg);
171 return hr;