mshtml: Added IHTMLCommentElement stub implementation.
[wine.git] / dlls / dxerr9 / dxerr9.c
blob7eabff1d28cb54609c1a2c38fc6b092e4f163f81
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 "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
32 #include "mmsystem.h"
33 #include "dmerror.h"
34 #include "ddraw.h"
35 #include "dinput.h"
36 #include "vfwmsgs.h"
37 #include "mmstream.h"
38 #include "dplay8.h"
39 #include "dxfile.h"
40 #include "d3d9.h"
41 #include "dsound.h"
43 #include "dxerr9.h"
45 typedef struct {
46 HRESULT hr;
47 const CHAR* resultA;
48 const WCHAR* resultW;
49 const CHAR* descriptionA;
50 const WCHAR* descriptionW;
51 } error_info;
53 #include "errors.h"
55 const char * WINAPI DXGetErrorString9A(HRESULT hr)
57 unsigned int i, j, k = 0;
59 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
60 j = k + (i / 2);
61 if (hr == info[j].hr)
62 return info[j].resultA;
63 if ((unsigned int)hr > (unsigned int)info[j].hr) {
64 k = j + 1;
65 i--;
69 return "Unknown";
72 const WCHAR * WINAPI DXGetErrorString9W(HRESULT hr)
74 static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
75 unsigned int i, j, k = 0;
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 DXGetErrorDescription9A(HRESULT hr)
92 unsigned int i, j, k = 0;
94 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
95 j = k + (i / 2);
96 if (hr == info[j].hr)
97 return info[j].descriptionA;
98 if ((unsigned int)hr > (unsigned int)info[j].hr) {
99 k = j + 1;
100 i--;
104 return "n/a";
107 const WCHAR * WINAPI DXGetErrorDescription9W(HRESULT hr)
109 static const WCHAR na[] = { 'n', '/', 'a', 0 };
110 unsigned int i, j, k = 0;
112 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
113 j = k + (i / 2);
114 if (hr == info[j].hr)
115 return info[j].descriptionW;
116 if ((unsigned int)hr > (unsigned int)info[j].hr) {
117 k = j + 1;
118 i--;
122 return na;
125 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
127 char msg[1024];
129 if (bPopMsgBox) {
130 snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
131 strFile, dwLine, DXGetErrorString9A(hr), hr, strMsg);
132 MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
133 } else {
134 snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
135 dwLine, strMsg, DXGetErrorString9A(hr), hr);
136 OutputDebugStringA(msg);
139 return hr;
142 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
144 WCHAR msg[1024];
146 if (bPopMsgBox) {
147 static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
148 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
149 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
150 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
151 static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
152 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
153 /* FIXME: should use wsnprintf */
154 wsprintfW(msg, format, strFile, dwLine,
155 DXGetErrorString9W(hr), hr, strMsg);
156 MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
157 } else {
158 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
159 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
160 0 };
161 /* FIXME: should use wsnprintf */
162 wsprintfW(msg, format, strFile, dwLine, strMsg,
163 DXGetErrorString9W(hr), hr);
164 OutputDebugStringW(msg);
167 return hr;