wined3d: Pass a wined3d_state structure to use_vs().
[wine/multimedia.git] / dlls / dxerr9 / dxerr9.c
blobc65f48e391edc6746fc91c7680bea73816a9f942
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"
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
31 #include "mmsystem.h"
32 #include "dmerror.h"
33 #include "ddraw.h"
34 #include "dinput.h"
35 #include "vfwmsgs.h"
36 #include "mmstream.h"
37 #include "dplay8.h"
38 #include "dxfile.h"
39 #include "d3d9.h"
40 #include "dsound.h"
42 #include "dxerr9.h"
44 typedef struct {
45 HRESULT hr;
46 const CHAR* resultA;
47 const WCHAR* resultW;
48 const CHAR* descriptionA;
49 const WCHAR* descriptionW;
50 } error_info;
52 #include "errors.h"
54 const char * WINAPI DXGetErrorString9A(HRESULT hr)
56 unsigned int i, j, k = 0;
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 DXGetErrorString9W(HRESULT hr)
73 static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
74 unsigned int i, j, k = 0;
76 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
77 j = k + (i / 2);
78 if (hr == info[j].hr)
79 return info[j].resultW;
80 if ((unsigned int)hr > (unsigned int)info[j].hr) {
81 k = j + 1;
82 i--;
86 return unknown;
89 const char * WINAPI DXGetErrorDescription9A(HRESULT hr)
91 unsigned int i, j, k = 0;
93 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
94 j = k + (i / 2);
95 if (hr == info[j].hr)
96 return info[j].descriptionA;
97 if ((unsigned int)hr > (unsigned int)info[j].hr) {
98 k = j + 1;
99 i--;
103 return "n/a";
106 const WCHAR * WINAPI DXGetErrorDescription9W(HRESULT hr)
108 static const WCHAR na[] = { 'n', '/', 'a', 0 };
109 unsigned int i, j, k = 0;
111 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
112 j = k + (i / 2);
113 if (hr == info[j].hr)
114 return info[j].descriptionW;
115 if ((unsigned int)hr > (unsigned int)info[j].hr) {
116 k = j + 1;
117 i--;
121 return na;
124 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
126 char msg[1024];
128 if (bPopMsgBox) {
129 snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
130 strFile, dwLine, DXGetErrorString9A(hr), hr, strMsg);
131 MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
132 } else {
133 snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
134 dwLine, strMsg, DXGetErrorString9A(hr), hr);
135 OutputDebugStringA(msg);
138 return hr;
141 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
143 WCHAR msg[1024];
145 if (bPopMsgBox) {
146 static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
147 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
148 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
149 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
150 static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
151 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
152 /* FIXME: should use wsnprintf */
153 wsprintfW(msg, format, strFile, dwLine,
154 DXGetErrorString9W(hr), hr, strMsg);
155 MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
156 } else {
157 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
158 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
159 0 };
160 /* FIXME: should use wsnprintf */
161 wsprintfW(msg, format, strFile, dwLine, strMsg,
162 DXGetErrorString9W(hr), hr);
163 OutputDebugStringW(msg);
166 return hr;