wined3d: Add missing check for p8 primary in surface_download_data.
[wine.git] / dlls / dxerr8 / dxerr8.c
blob69d24e65017e7db61e01925e63a564715021a2d3
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
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 "dsound.h"
34 #include "dmerror.h"
35 #include "ddraw.h"
36 #include "dinput.h"
37 #include "vfwmsgs.h"
39 #include "dxerr8.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
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 DXGetErrorString8A(HRESULT hr)
57 unsigned int i, j, k = 0;
58 TRACE("(0x%08x)\n", hr);
60 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
61 j = k + (i / 2);
62 if (hr == info[j].hr)
63 return info[j].resultA;
64 if ((unsigned int)hr > (unsigned int)info[j].hr) {
65 k = j + 1;
66 i--;
70 return "Unknown";
73 const WCHAR * WINAPI DXGetErrorString8W(HRESULT hr)
75 static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
76 unsigned int i, j, k = 0;
77 TRACE("(0x%08x)\n", hr);
79 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
80 j = k + (i / 2);
81 if (hr == info[j].hr)
82 return info[j].resultW;
83 if ((unsigned int)hr > (unsigned int)info[j].hr) {
84 k = j + 1;
85 i--;
89 return unknown;
92 const char * WINAPI DXGetErrorDescription8A(HRESULT hr)
94 unsigned int i, j, k = 0;
95 TRACE("(0x%08x)\n", hr);
97 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
98 j = k + (i / 2);
99 if (hr == info[j].hr)
100 return info[j].descriptionA;
101 if ((unsigned int)hr > (unsigned int)info[j].hr) {
102 k = j + 1;
103 i--;
107 return "n/a";
110 const WCHAR * WINAPI DXGetErrorDescription8W(HRESULT hr)
112 static const WCHAR na[] = { 'n', '/', 'a', 0 };
113 unsigned int i, j, k = 0;
114 TRACE("(0x%08x)\n", hr);
116 for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
117 j = k + (i / 2);
118 if (hr == info[j].hr)
119 return info[j].descriptionW;
120 if ((unsigned int)hr > (unsigned int)info[j].hr) {
121 k = j + 1;
122 i--;
126 return na;
129 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char* strMsg, BOOL bPopMsgBox)
131 char msg[1024];
132 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
134 if (bPopMsgBox) {
135 snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
136 strFile, dwLine, DXGetErrorString8A(hr), hr, strMsg);
137 MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
138 } else {
139 snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
140 dwLine, strMsg, DXGetErrorString8A(hr), hr);
141 OutputDebugStringA(msg);
144 return hr;
147 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
149 WCHAR msg[1024];
150 TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
152 if (bPopMsgBox) {
153 static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
154 'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
155 'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
156 '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
157 static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
158 'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
159 /* FIXME: should use wsnprintf */
160 wsprintfW(msg, format, strFile, dwLine,
161 DXGetErrorString8W(hr), hr, strMsg);
162 MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
163 } else {
164 static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
165 'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
166 0 };
167 /* FIXME: should use wsnprintf */
168 wsprintfW(msg, format, strFile, dwLine, strMsg,
169 DXGetErrorString8W(hr), hr);
170 OutputDebugStringW(msg);
173 return hr;