systray: Add support for NIS_HIDDEN flag.
[wine.git] / dlls / dxerr9 / dxerr9.c
blob63822d27b3453b8fa827e125b8903526fb4e9a2d
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"
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 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
46 typedef struct {
47 HRESULT hr;
48 const CHAR* resultA;
49 const WCHAR* resultW;
50 const CHAR* descriptionA;
51 const WCHAR* descriptionW;
52 } error_info;
54 #include "errors.h"
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) {
62 j = k + (i / 2);
63 if (hr == info[j].hr)
64 return info[j].resultA;
65 if ((unsigned int)hr > (unsigned int)info[j].hr) {
66 k = j + 1;
67 i--;
71 return "Unknown";
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) {
81 j = k + (i / 2);
82 if (hr == info[j].hr)
83 return info[j].resultW;
84 if ((unsigned int)hr > (unsigned int)info[j].hr) {
85 k = j + 1;
86 i--;
90 return unknown;
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) {
99 j = k + (i / 2);
100 if (hr == info[j].hr)
101 return info[j].descriptionA;
102 if ((unsigned int)hr > (unsigned int)info[j].hr) {
103 k = j + 1;
104 i--;
108 return "n/a";
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) {
118 j = k + (i / 2);
119 if (hr == info[j].hr)
120 return info[j].descriptionW;
121 if ((unsigned int)hr > (unsigned int)info[j].hr) {
122 k = j + 1;
123 i--;
127 return na;
130 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
132 char msg[1024];
133 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
135 if (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);
139 } else {
140 snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
141 dwLine, strMsg, DXGetErrorString9A(hr), hr);
142 OutputDebugStringA(msg);
145 return hr;
148 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
150 WCHAR msg[1024];
151 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
153 if (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);
164 } else {
165 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
166 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
167 0 };
168 /* FIXME: should use wsnprintf */
169 wsprintfW(msg, format, strFile, dwLine, strMsg,
170 DXGetErrorString9W(hr), hr);
171 OutputDebugStringW(msg);
174 return hr;