widl: Initialize local variables in stub functions.
[wine/hacks.git] / dlls / dxerr9 / dxerr9.c
blobff2a5c4ccee6a9f04dc1a6d48b890215530d35d7
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
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 "dmerror.h"
32 #include "ddraw.h"
33 #include "dinput.h"
34 #include "vfwmsgs.h"
35 #include "mmstream.h"
36 #include "dplay8.h"
37 #include "dxfile.h"
38 #include "d3d9.h"
39 #include "dsound.h"
41 #include "dxerr9.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
47 typedef struct {
48 HRESULT hr;
49 const CHAR* resultA;
50 const WCHAR* resultW;
51 const CHAR* descriptionA;
52 const WCHAR* descriptionW;
53 } error_info;
55 #include "errors.h"
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) {
63 j = k + (i / 2);
64 if (hr == info[j].hr)
65 return info[j].resultA;
66 if ((unsigned int)hr > (unsigned int)info[j].hr) {
67 k = j + 1;
68 i--;
72 return "Unknown";
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) {
82 j = k + (i / 2);
83 if (hr == info[j].hr)
84 return info[j].resultW;
85 if ((unsigned int)hr > (unsigned int)info[j].hr) {
86 k = j + 1;
87 i--;
91 return unknown;
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) {
100 j = k + (i / 2);
101 if (hr == info[j].hr)
102 return info[j].descriptionA;
103 if ((unsigned int)hr > (unsigned int)info[j].hr) {
104 k = j + 1;
105 i--;
109 return "n/a";
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) {
119 j = k + (i / 2);
120 if (hr == info[j].hr)
121 return info[j].descriptionW;
122 if ((unsigned int)hr > (unsigned int)info[j].hr) {
123 k = j + 1;
124 i--;
128 return na;
131 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
133 char msg[1024];
134 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
136 if (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);
140 } else {
141 snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
142 dwLine, strMsg, DXGetErrorString9A(hr), hr);
143 OutputDebugStringA(msg);
146 return hr;
149 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
151 WCHAR msg[1024];
152 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
154 if (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);
165 } else {
166 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
167 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
168 0 };
169 /* FIXME: should use wsnprintf */
170 wsprintfW(msg, format, strFile, dwLine, strMsg,
171 DXGetErrorString9W(hr), hr);
172 OutputDebugStringW(msg);
175 return hr;