d3d9: Remove some spamy debug traces from the texture test.
[wine] / dlls / dxerr8 / dxerr8.c
1 /*
2  * DirectX 8 error routines
3  *
4  * Copyright 2004-2005 Robert Reif
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28
29 #include "mmsystem.h"
30 #include "dsound.h"
31 #include "dmerror.h"
32 #include "ddraw.h"
33 #include "dinput.h"
34 #include "vfwmsgs.h"
35
36 #include "dxerr8.h"
37
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
41
42 typedef struct {
43     HRESULT      hr;
44     const CHAR*  resultA;
45     const WCHAR* resultW;
46     const CHAR*  descriptionA;
47     const WCHAR* descriptionW;
48 } error_info;
49
50 #include "errors.h"
51
52 const char * WINAPI DXGetErrorString8A(HRESULT hr)
53 {
54     unsigned int i, j, k = 0;
55     TRACE("(0x%08x)\n", hr);
56
57     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
58         j = k + (i / 2);
59         if (hr == info[j].hr)
60             return info[j].resultA;
61         if ((unsigned int)hr > (unsigned int)info[j].hr) {
62             k = j + 1;
63             i--;
64         }
65     }
66
67     return "Unknown";
68 }
69
70 const WCHAR * WINAPI DXGetErrorString8W(HRESULT hr)
71 {
72     static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
73     unsigned int i, j, k = 0;
74     TRACE("(0x%08x)\n", hr);
75
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--;
83         }
84     }
85
86     return unknown;
87 }
88
89 const char * WINAPI DXGetErrorDescription8A(HRESULT hr)
90 {
91     unsigned int i, j, k = 0;
92     TRACE("(0x%08x)\n", hr);
93
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--;
101         }
102     }
103
104     return "n/a";
105 }
106
107 const WCHAR * WINAPI DXGetErrorDescription8W(HRESULT hr)
108 {
109     static const WCHAR na[] = { 'n', '/', 'a', 0 };
110     unsigned int i, j, k = 0;
111     TRACE("(0x%08x)\n", hr);
112
113     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
114         j = k + (i / 2);
115         if (hr == info[j].hr)
116             return info[j].descriptionW;
117         if ((unsigned int)hr > (unsigned int)info[j].hr) {
118             k = j + 1;
119             i--;
120         }
121     }
122
123     return na;
124 }
125
126 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char*  strMsg, BOOL bPopMsgBox)
127 {
128     char msg[1024];
129     TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
130
131     if (bPopMsgBox) {
132         snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
133             strFile, dwLine, DXGetErrorString8A(hr), hr, strMsg);
134         MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
135     } else {
136         snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
137             dwLine, strMsg, DXGetErrorString8A(hr), hr);
138         OutputDebugStringA(msg);
139     }
140
141     return hr;
142 }
143
144 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
145 {
146     WCHAR msg[1024];
147     TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
148
149     if (bPopMsgBox) {
150         static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
151             'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
152             'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
153             '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
154         static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
155             'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
156         /* FIXME: should use wsnprintf */
157         wsprintfW(msg, format, strFile, dwLine,
158                   DXGetErrorString8W(hr), hr, strMsg);
159         MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
160     } else {
161         static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
162             'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
163             0 };
164         /* FIXME: should use wsnprintf */
165         wsprintfW(msg, format, strFile, dwLine, strMsg,
166                   DXGetErrorString8W(hr), hr);
167         OutputDebugStringW(msg);
168     }
169
170     return hr;
171 }