wined3d: Create a backup context if setting the pixel format failed in wined3d_contex...
[wine.git] / dlls / dxerr8 / dxerr8.c
blobeb723941245222f85846c429e076bd4b03f5ebc6
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
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
29 #include "mmsystem.h"
30 #include "dsound.h"
31 #include "dmerror.h"
32 #include "ddraw.h"
33 #include "dinput.h"
34 #include "vfwmsgs.h"
36 #include "dxerr8.h"
38 typedef struct {
39 HRESULT hr;
40 const CHAR* resultA;
41 const WCHAR* resultW;
42 const CHAR* descriptionA;
43 const WCHAR* descriptionW;
44 } error_info;
46 #include "errors.h"
48 const char * WINAPI DXGetErrorString8A(HRESULT hr)
50 unsigned int i, j, k = 0;
52 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
53 j = k + (i / 2);
54 if (hr == info[j].hr)
55 return info[j].resultA;
56 if ((unsigned int)hr > (unsigned int)info[j].hr) {
57 k = j + 1;
58 i--;
62 return "Unknown";
65 const WCHAR * WINAPI DXGetErrorString8W(HRESULT hr)
67 static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
68 unsigned int i, j, k = 0;
70 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
71 j = k + (i / 2);
72 if (hr == info[j].hr)
73 return info[j].resultW;
74 if ((unsigned int)hr > (unsigned int)info[j].hr) {
75 k = j + 1;
76 i--;
80 return unknown;
83 const char * WINAPI DXGetErrorDescription8A(HRESULT hr)
85 unsigned int i, j, k = 0;
87 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
88 j = k + (i / 2);
89 if (hr == info[j].hr)
90 return info[j].descriptionA;
91 if ((unsigned int)hr > (unsigned int)info[j].hr) {
92 k = j + 1;
93 i--;
97 return "n/a";
100 const WCHAR * WINAPI DXGetErrorDescription8W(HRESULT hr)
102 static const WCHAR na[] = { 'n', '/', 'a', 0 };
103 unsigned int i, j, k = 0;
105 for (i = ARRAY_SIZE(info); i != 0; i /= 2) {
106 j = k + (i / 2);
107 if (hr == info[j].hr)
108 return info[j].descriptionW;
109 if ((unsigned int)hr > (unsigned int)info[j].hr) {
110 k = j + 1;
111 i--;
115 return na;
118 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
120 char msg[1024];
122 if (bPopMsgBox) {
123 wsprintfA(msg, "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
124 strFile, dwLine, DXGetErrorString8A(hr), hr, strMsg);
125 MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
126 } else {
127 wsprintfA(msg, "%s(%d): %s (hr=%s (0x%08x))", strFile,
128 dwLine, strMsg, DXGetErrorString8A(hr), hr);
129 OutputDebugStringA(msg);
132 return hr;
135 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
137 WCHAR msg[1024];
139 if (bPopMsgBox) {
140 static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
141 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
142 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
143 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
144 static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
145 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
146 /* FIXME: should use wsnprintf */
147 wsprintfW(msg, format, strFile, dwLine,
148 DXGetErrorString8W(hr), hr, strMsg);
149 MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
150 } else {
151 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
152 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
153 0 };
154 /* FIXME: should use wsnprintf */
155 wsprintfW(msg, format, strFile, dwLine, strMsg,
156 DXGetErrorString8W(hr), hr);
157 OutputDebugStringW(msg);
160 return hr;