]> icculus.org git repositories - btb/d2x.git/blob - arch/win32/debug.cpp
Moved arch/sdl_* to arch/sdl
[btb/d2x.git] / arch / win32 / debug.cpp
1 /*
2 **-----------------------------------------------------------------------------
3 ** Name:    Debug.cpp
4 ** Purpose: Example debug code for D3D sample
5 ** Notes:
6 **
7 ** Copyright (C) 199 - 1997 Microsoft Corporation. All Rights Reserved.
8 **-----------------------------------------------------------------------------
9 */
10
11 /*
12 **-----------------------------------------------------------------------------
13 ** Includes
14 **-----------------------------------------------------------------------------
15 */
16
17 #include "pch.h"
18 #include "Debug.h"
19 extern "C" {
20 #include "WinMain.h"
21 }
22
23
24 /*
25 **-----------------------------------------------------------------------------
26 ** Global variables
27 **-----------------------------------------------------------------------------
28 */
29 #define MAX_STRING 256
30
31 #ifndef NDEBUG
32     DWORD   g_dwDebugLevel = DEBUG_ALWAYS;
33     BOOL    g_fDebug = TRUE;
34 #else
35     BOOL    g_fDebug = FALSE;
36 #endif
37
38
39
40 /*
41 **-----------------------------------------------------------------------------
42 ** Local prototypes
43 **-----------------------------------------------------------------------------
44 */
45
46 extern "C"
47 BOOL GetDDErrorString (HRESULT hResult, LPTSTR lpszError, DWORD cchError);
48
49
50
51 /*
52 **-----------------------------------------------------------------------------
53 ** Functions
54 **-----------------------------------------------------------------------------
55 */
56
57
58 /*
59 **-----------------------------------------------------------------------------
60 **  Name:       dprintf
61 **  Purpose:    Printf to debug output
62 **-----------------------------------------------------------------------------
63 */
64
65 #ifndef NDEBUG
66 void __cdecl dprintf (DWORD dwDebugLevel, LPCTSTR szFormat, ...)
67 {
68     TCHAR   szBuffer[MAX_STRING];
69     va_list va;
70
71         // Check if current debug level
72     if (dwDebugLevel < g_dwDebugLevel)
73             return;
74     
75     lstrcpy (szBuffer, START_STR);
76     va_start(va, szFormat);
77     wvsprintf (szBuffer+lstrlen (szBuffer), szFormat, va);
78     va_end(va);
79     lstrcat (szBuffer, END_STR);
80     OutputDebugString (szBuffer);
81 }
82 #endif // NDEBUG
83
84
85
86 /*
87 **-----------------------------------------------------------------------------
88 ** Name:    ReportDDError
89 ** Purpose: 
90 **-----------------------------------------------------------------------------
91 */
92
93 void _cdecl ReportDDError (HRESULT hResult, LPCTSTR szFormat, ...)
94 {
95     TCHAR   szMsg[MAX_STRING];
96     TCHAR   szErr[MAX_STRING];
97     TCHAR   szUnknown[] = TEXT("Unknown");
98     DWORD   cchErr = sizeof(szErr)/sizeof(TCHAR);
99     va_list va;
100
101     // Check for Success Error code
102     if (hResult == DD_OK)
103         return;
104
105     va_start( va, szFormat );
106     wvsprintf (szMsg, szFormat, va);
107     va_end( va );
108
109     // Get DD/D3D error string
110     szErr[0] = 0;
111     GetDDErrorString (hResult, szErr, cchErr);    
112     wsprintf (szMsg + strlen (szMsg), TEXT(" : DD/D3D Error = %s\r\n"), szErr);
113
114
115     // Dump to debugger
116     DPF (DEBUG_ERROR, TEXT("%s"), szMsg);
117
118         //
119         // Define the following if you want an in your face Messagebox on errors
120         //
121 //#define DEBUG_PROMPTME
122 #ifdef DEBUG_PROMPTME
123     HWND    hWindow;
124
125     // Pause App
126         if (g_hWnd)
127                 OnPause (g_hWnd, TRUE);
128
129     // Display Error Message to user
130     if (g_hWnd)
131         hWindow = g_hWnd;
132     else
133         hWindow = NULL;
134
135     MessageBox (hWindow, szMsg, g_szMainTitle, MB_OK | MB_APPLMODAL);
136
137     // Unpause app
138         if (g_hWnd)
139                 OnPause (g_hWnd, FALSE);
140 #endif
141
142 } // ReportDDError
143
144
145 #ifndef NDEBUG
146 ULONG CDebugTracker::s_cLevels = 0;
147 char CDebugTracker::szsp [80];
148
149 CDebugTracker::CDebugTracker (LPCSTR lpsz)
150 {
151         m_psz = strdup (lpsz);
152         m_bReturned = FALSE;
153
154         szsp [s_cLevels] = '/';
155         szsp [s_cLevels + 1] = '\0';
156         DPF (DEBUG_ALWAYS, "%s%s start", szsp, m_psz);
157         szsp [s_cLevels] = '|';
158         s_cLevels++;
159 }
160
161 CDebugTracker::~CDebugTracker ()
162 {
163         s_cLevels--;
164         if (!m_bReturned)
165         {
166                 szsp [s_cLevels + 1] = '\0';
167                 szsp [s_cLevels] = '\\';
168                 DPF (DEBUG_ALWAYS, "%s%s end", szsp, m_psz);
169         }
170         free ((LPVOID) m_psz);
171 }
172
173 void __cdecl Return (LPCSTR szFormat, ...)
174 {
175 }
176 #endif
177
178 /*
179 **-----------------------------------------------------------------------------
180 ** Name:    GetDDErrorString
181 ** Purpose: outputs a debug string to debugger
182 **-----------------------------------------------------------------------------
183 */
184
185 extern "C" 
186 BOOL GetDDErrorString (HRESULT hResult, LPTSTR lpszErrorBuff, DWORD cchError)
187 {
188     DWORD  cLen;
189     LPTSTR lpszError;
190     TCHAR  szMsg[MAX_STRING];
191
192     // Check parameters
193     if (!lpszErrorBuff || !cchError)
194     {
195         // Error, invalid parameters
196         return FALSE;
197     }
198
199     switch (hResult)
200     {
201     case DD_OK:
202         // The request completed successfully.
203         lpszError = TEXT("DD_OK");
204         break;
205
206     case DDERR_ALREADYINITIALIZED:
207         // The object has already been initialized.
208         lpszError = TEXT("DDERR_ALREADYINITIALIZED");
209         break;
210
211     case DDERR_BLTFASTCANTCLIP:
212         // A DirectDrawClipper object is attached to a source surface 
213         // that has passed into a call to the IDirectDrawSurface4::BltFast method. 
214         lpszError = TEXT("DDERR_BLTFASTCANTCLIP");
215         break;
216
217     case DDERR_CANNOTATTACHSURFACE:
218         // A surface cannot be attached to another requested surface. 
219         lpszError = TEXT("DDERR_CANNOTATTACHSURFACE");
220         break;
221
222     case DDERR_CANNOTDETACHSURFACE:
223         // A surface cannot be detached from another requested surface. 
224         lpszError = TEXT("DDERR_CANNOTDETACHSURFACE");
225         break;
226
227     case DDERR_CANTCREATEDC:
228         // Windows cannot create any more device contexts (DCs). 
229         lpszError = TEXT("DDERR_CANTCREATEDC");
230         break;
231
232     case DDERR_CANTDUPLICATE:
233         // Primary and 3D surfaces, or surfaces that are 
234         // implicitly created, cannot be duplicated. 
235         lpszError = TEXT("DDERR_CANTDUPLICATE");
236         break;
237
238     case DDERR_CANTLOCKSURFACE:
239         // Access to this surface is refused because an 
240         // attempt was made to lock the primary surface without DCI support. 
241         lpszError = TEXT("DDERR_CANTLOCKSURFACE"); 
242         break;
243
244     case DDERR_CANTPAGELOCK:
245         // An attempt to page lock a surface failed. 
246         // Page lock will not work on a display-memory 
247         // surface or an emulated primary surface.
248         lpszError = TEXT("DDERR_CANTPAGELOCK"); 
249         break;
250
251     case DDERR_CANTPAGEUNLOCK:
252         // An attempt to page unlock a surface failed. 
253         // Page unlock will not work on a display-memory 
254         // surface or an emulated primary surface. 
255         lpszError = TEXT("DDERR_CANTPAGEUNLOCK");
256         break;
257
258     case DDERR_CLIPPERISUSINGHWND:
259         // An attempt was made to set a clip list for a DirectDrawClipper 
260         // object that is already monitoring a window handle. 
261         lpszError = TEXT("DDERR_CLIPPERISUSINGHWND");
262         break;
263
264     case DDERR_COLORKEYNOTSET:
265         // No source color key is specified for this operation
266         lpszError = TEXT("DDERR_COLORKEYNOTSET");
267         break;
268
269     case DDERR_CURRENTLYNOTAVAIL:
270         // No support is currently available. 
271         lpszError = TEXT("DDERR_CURRENTLYNOTAVAIL");
272         break;
273
274     case DDERR_DCALREADYCREATED:
275         // A device context (DC) has already been returned for this surface. 
276         // Only one DC can be retrieved for each surface. 
277         lpszError = TEXT("DDERR_DCALREADYCREATED");
278         break;
279
280     case DDERR_DIRECTDRAWALREADYCREATED:
281         // A DirectDraw object representing this driver 
282         // has already been created for this process. 
283         lpszError = TEXT("DDERR_DIRECTDRAWALREADYCREATED");
284         break;
285
286     case DDERR_EXCEPTION:
287         // An exception was encountered while 
288         // performing the requested operation. 
289         lpszError = TEXT("DDERR_EXCEPTION");
290         break;
291
292     case DDERR_EXCLUSIVEMODEALREADYSET:
293         // An attempt was made to set the cooperative 
294         // level when it was already set to exclusive. 
295         lpszError = TEXT("DDERR_EXCLUSIVEMODEALREADYSET");
296         break;
297
298     case DDERR_GENERIC:
299         // There is an undefined error condition. 
300         lpszError = TEXT("DDERR_GENERIC");
301         break;
302
303     case DDERR_HEIGHTALIGN:
304         // The height of the provided rectangle 
305         // is not a multiple of the required alignment. 
306         lpszError = TEXT("DDERR_HEIGHTALIGN");
307         break;
308
309     case DDERR_HWNDALREADYSET:
310         // The DirectDraw cooperative level window 
311         // handle has already been set. It cannot 
312         // be reset while the process has surfaces or palettes created. 
313         lpszError = TEXT("DDERR_HWNDALREADYSET");
314         break;
315
316     case DDERR_HWNDSUBCLASSED:
317         // DirectDraw is prevented from restoring state because the
318         // DirectDraw cooperative level window handle has been subclassed. 
319         lpszError = TEXT("DDERR_HWNDSUBCLASSED");
320         break;
321
322     case DDERR_IMPLICITLYCREATED:
323         // The surface cannot be restored because 
324         // it is an implicitly created surface. 
325         lpszError = TEXT("DDERR_IMPLICITLYCREATED");
326         break;
327  
328     case DDERR_INCOMPATIBLEPRIMARY:
329         // The primary surface creation request 
330         // does not match with the existing primary surface. 
331         lpszError = TEXT("DDERR_INCOMPATIBLEPRIMARY");
332         break;
333
334     case DDERR_INVALIDCAPS:
335         // One or more of the capability bits 
336         // passed to the callback function are incorrect. 
337         lpszError = TEXT("DDERR_INVALIDCAPS");
338         break;
339
340     case DDERR_INVALIDCLIPLIST:
341         // DirectDraw does not support the provided clip list.  
342         lpszError = TEXT("DDERR_INVALIDCLIPLIST");
343         break;
344
345     case DDERR_INVALIDDIRECTDRAWGUID:
346         // The globally unique identifier (GUID) passed to the
347         // DirectDrawCreate function is not a valid DirectDraw driver identifier. 
348         lpszError = TEXT("DDERR_INVALIDDIRECTDRAWGUID");
349         break;
350
351     case DDERR_INVALIDMODE:
352         // DirectDraw does not support the requested mode. 
353         lpszError = TEXT("DDERR_INVALIDMODE");
354         break;
355
356     case DDERR_INVALIDOBJECT:
357         // DirectDraw received a pointer that was an invalid DirectDraw object. 
358         lpszError = TEXT("DDERR_INVALIDOBJECT");
359         break;
360
361     case DDERR_INVALIDPARAMS:
362         // One or more of the parameters passed to the method are incorrect. 
363         lpszError = TEXT("DDERR_INVALIDPARAMS");
364         break;
365
366     case DDERR_INVALIDPIXELFORMAT:
367         // The pixel format was invalid as specified. 
368         lpszError = TEXT("DDERR_INVALIDPIXELFORMAT");
369         break;
370
371     case DDERR_INVALIDPOSITION:
372         // The position of the overlay on the destination is no longer legal. 
373         lpszError = TEXT("DDERR_INVALIDPOSITION");
374         break;
375
376     case DDERR_INVALIDRECT:
377         // The provided rectangle was invalid. 
378         lpszError = TEXT("DDERR_INVALIDRECT");
379         break;
380
381     case DDERR_INVALIDSURFACETYPE:
382         // The requested operation could not be performed
383         // because the surface was of the wrong type. 
384         lpszError = TEXT("DDERR_INVALIDSURFACETYPE");
385         break;
386
387     case DDERR_LOCKEDSURFACES:
388         // One or more surfaces are locked, 
389         // causing the failure of the requested operation. 
390         lpszError = TEXT("DDERR_LOCKEDSURFACES");
391         break;
392
393     case DDERR_MOREDATA:
394         // There is more data available than the specified 
395         // buffer size could hold.
396         lpszError = TEXT("DDERR_MOREDATA");
397         break;
398
399     case DDERR_NO3D:
400         // No 3D hardware or emulation is present. 
401         lpszError = TEXT("DDERR_NO3D");
402         break;
403
404     case DDERR_NOALPHAHW:
405         // No alpha acceleration hardware is present or available, 
406         // causing the failure of the requested operation. 
407         lpszError = TEXT("DDERR_NOALPHAHW");
408         break;
409
410     case DDERR_NOBLTHW:
411         // No blitter hardware is present. 
412         lpszError = TEXT("DDERR_NOBLTHW");
413         break;
414
415     case DDERR_NOCLIPLIST:
416         // No clip list is available. 
417         lpszError = TEXT("DDERR_NOCLIPLIST");
418         break;
419
420     case DDERR_NOCLIPPERATTACHED:
421         // No DirectDrawClipper object is attached to the surface object. 
422         lpszError = TEXT("DDERR_NOCLIPPERATTACHED");
423         break;
424
425     case DDERR_NOCOLORCONVHW:
426         // The operation cannot be carried out because 
427         // no color-conversion hardware is present or available. 
428         lpszError = TEXT("DDERR_NOCOLORCONVHW");
429         break;
430
431     case DDERR_NOCOLORKEY:
432         // The surface does not currently have a color key. 
433         lpszError = TEXT("DDERR_NOCOLORKEY");
434         break;
435
436     case DDERR_NOCOLORKEYHW:
437         // The operation cannot be carried out because there 
438         // is no hardware support for the destination color key. 
439         lpszError = TEXT("DDERR_NOCOLORKEYHW");
440         break;
441
442     case DDERR_NOCOOPERATIVELEVELSET:
443         // A create function is called without the 
444         // IDirectDraw2::SetCooperativeLevel method being called. 
445         lpszError = TEXT("DDERR_NOCOOPERATIVELEVELSET");
446         break;
447
448     case DDERR_NODC:
449         // No DC has ever been created for this surface. 
450         lpszError = TEXT("DDERR_NODC");
451         break;
452
453     case DDERR_NODDROPSHW:
454         // No DirectDraw raster operation (ROP) hardware is available. 
455         lpszError = TEXT("DDERR_NODDROPSHW");
456         break;
457
458     case DDERR_NODIRECTDRAWHW:
459         // Hardware-only DirectDraw object creation is not possible; 
460         // the driver does not support any hardware. 
461         lpszError = TEXT("DDERR_NODIRECTDRAWHW");
462         break;
463
464     case DDERR_NODIRECTDRAWSUPPORT:
465         // DirectDraw support is not possible with the current display driver. 
466         lpszError = TEXT("DDERR_NODIRECTDRAWSUPPORT");
467         break;
468
469     case DDERR_NOEMULATION: 
470         // Software emulation is not available. 
471         lpszError = TEXT("DDERR_NOEMULATION");
472         break;
473
474     case DDERR_NOEXCLUSIVEMODE:
475         // The operation requires the application to have 
476         // exclusive mode, but the application does not have exclusive mode. 
477         lpszError = TEXT("DDERR_NOEXCLUSIVEMODE");
478         break;
479
480     case DDERR_NOFLIPHW: 
481         // Flipping visible surfaces is not supported. 
482         lpszError = TEXT("DDERR_NOFLIPHW");
483         break;
484
485     case DDERR_NOGDI: 
486         // No GDI is present. 
487         lpszError = TEXT("DDERR_NOGDI");
488         break;
489
490     case DDERR_NOHWND: 
491         // Clipper notification requires a window handle, 
492         // or no window handle has been previously set 
493         // as the cooperative level window handle. 
494         lpszError = TEXT("DDERR_NOHWND");
495         break;
496
497     case DDERR_NOMIPMAPHW: 
498         // The operation cannot be carried out because no 
499         // mipmap texture mapping hardware is present or available. 
500         lpszError = TEXT("DDERR_NOMIPMAPHW");
501         break;
502
503     case DDERR_NOMIRRORHW: 
504         // The operation cannot be carried out because 
505         // no mirroring hardware is present or available. 
506         lpszError = TEXT("DDERR_NOMIRRORHW");
507         break;
508
509     case DDERR_NONONLOCALVIDMEM: 
510         // An attempt was made to allocate non-local video memory
511         // from a device that does not support non-local video memory.
512         lpszError = TEXT("DDERR_NONONLOCALVIDMEM");
513         break;
514  
515     case DDERR_NOOVERLAYDEST: 
516         // The IDirectDrawSurface4::GetOverlayPosition method 
517         // is called on an overlay that the IDirectDrawSurface4::UpdateOverlay 
518         // method has not been called on to establish a destination. 
519         lpszError = TEXT("DDERR_NOOVERLAYDEST");
520         break;
521
522     case DDERR_NOOVERLAYHW: 
523         // The operation cannot be carried out because 
524         // no overlay hardware is present or available. 
525         lpszError = TEXT("DDERR_NOOVERLAYHW");
526         break;
527
528     case DDERR_NOPALETTEATTACHED: 
529         // No palette object is attached to this surface. 
530         lpszError = TEXT("DDERR_NOPALETTEATTACHED");
531         break;
532
533     case DDERR_NOPALETTEHW: 
534         // There is no hardware support for 16- or 256-color palettes. 
535         lpszError = TEXT("DDERR_NOPALETTEHW");
536         break;
537
538     case DDERR_NORASTEROPHW: 
539         // The operation cannot be carried out because 
540         // no appropriate raster operation hardware is present or available. 
541         lpszError = TEXT("DDERR_NORASTEROPHW");
542         break;
543
544     case DDERR_NOROTATIONHW: 
545         // The operation cannot be carried out because 
546         // no rotation hardware is present or available. 
547         lpszError = TEXT("DDERR_NOROTATIONHW");
548         break;
549
550     case DDERR_NOSTRETCHHW: 
551         // The operation cannot be carried out because 
552         // there is no hardware support for stretching. 
553         lpszError = TEXT("DDERR_NOSTRETCHHW");
554         break;
555
556     case DDERR_NOT4BITCOLOR: 
557         // The DirectDrawSurface object is not using a 
558         // 4-bit color palette and the requested operation 
559         // requires a 4-bit color palette. 
560         lpszError = TEXT("DDERR_NOT4BITCOLOR");
561         break;
562
563     case DDERR_NOT4BITCOLORINDEX: 
564         // The DirectDrawSurface object is not using a 4-bit 
565         // color index palette and the requested operation 
566         // requires a 4-bit color index palette. 
567         lpszError = TEXT("DDERR_NOT4BITCOLORINDEX");
568         break;
569
570     case DDERR_NOT8BITCOLOR: 
571         // The DirectDrawSurface object is not using an 8-bit 
572         // color palette and the requested operation requires 
573         // an 8-bit color palette. 
574         lpszError = TEXT("DDERR_NOT8BITCOLOR");
575         break;
576
577     case DDERR_NOTAOVERLAYSURFACE: 
578         // An overlay component is called for a non-overlay surface. 
579         lpszError = TEXT("DDERR_NOTAOVERLAYSURFACE");
580         break;
581
582     case DDERR_NOTEXTUREHW: 
583         // The operation cannot be carried out because no 
584         // texture-mapping hardware is present or available. 
585         lpszError = TEXT("DDERR_NOTEXTUREHW");
586         break;
587
588     case DDERR_NOTFLIPPABLE: 
589         // An attempt has been made to flip a surface that cannot be flipped. 
590         lpszError = TEXT("DDERR_NOTFLIPPABLE");
591         break;
592
593     case DDERR_NOTFOUND: 
594         // The requested item was not found. 
595         lpszError = TEXT("DDERR_NOTFOUND");
596         break;
597
598     case DDERR_NOTINITIALIZED: 
599         // An attempt was made to call an interface method of a DirectDraw object 
600         // created by CoCreateInstance before the object was initialized. 
601         lpszError = TEXT("DDERR_NOTINITIALIZED");
602         break;
603
604     case DDERR_NOTLOCKED: 
605         // An attempt is made to unlock a surface that was not locked. 
606         lpszError = TEXT("DDERR_NOTLOCKED");
607         break;
608
609     case DDERR_NOTPAGELOCKED: 
610         // An attempt is made to page unlock a surface 
611         // with no outstanding page locks. 
612         lpszError = TEXT("DDERR_NOTPAGELOCKED");
613         break;
614
615     case DDERR_NOTPALETTIZED: 
616         // The surface being used is not a palette-based surface. 
617         lpszError = TEXT("DDERR_NOTPALETTIZED");
618         break;
619
620     case DDERR_NOVSYNCHW: 
621         // The operation cannot be carried out because 
622         // there is no hardware support for vertical blank synchronized operations. 
623         lpszError = TEXT("DDERR_NOVSYNCHW");
624         break;
625
626     case DDERR_NOZBUFFERHW: 
627         // The operation to create a z-buffer in display memory 
628         // or to perform a blit using a z-buffer cannot be carried 
629         // out because there is no hardware support for z-buffers. 
630         lpszError = TEXT("DDERR_NOZBUFFERHW");
631         break;
632
633     case DDERR_NOZOVERLAYHW: 
634         // The overlay surfaces cannot be z-layered based 
635         // on the z-order because the hardware does not 
636         // support z-ordering of overlays. 
637         lpszError = TEXT("DDERR_NOZOVERLAYHW");
638         break;
639
640     case DDERR_OUTOFCAPS: 
641         // The hardware needed for the requested operation has already been allocated. 
642         lpszError = TEXT("DDERR_OUTOFCAPS");
643         break;
644
645     case DDERR_OUTOFMEMORY: 
646         // DirectDraw does not have enough memory to perform the operation. 
647         lpszError = TEXT("DDERR_OUTOFMEMORY");
648         break;
649
650     case DDERR_OUTOFVIDEOMEMORY: 
651         // DirectDraw does not have enough display memory to perform the operation. 
652         lpszError = TEXT("DDERR_OUTOFVIDEOMEMORY");
653         break;
654
655     case DDERR_OVERLAYCANTCLIP: 
656         // The hardware does not support clipped overlays. 
657         lpszError = TEXT("DDERR_OVERLAYCANTCLIP");
658         break;
659
660     case DDERR_OVERLAYCOLORKEYONLYONEACTIVE: 
661         // An attempt was made to have more than one color key active on an overlay. 
662         lpszError = TEXT("DDERR_OVERLAYCOLORKEYONLYONEACTIVE");
663         break;
664
665     case DDERR_OVERLAYNOTVISIBLE: 
666         // The IDirectDrawSurface4::GetOverlayPosition method is called on a hidden overlay. 
667         lpszError = TEXT("DDERR_OVERLAYNOTVISIBLE");
668         break;
669
670     case DDERR_PALETTEBUSY: 
671         // Access to this palette is refused 
672         // because the palette is locked by another thread. 
673         lpszError = TEXT("DDERR_PALETTEBUSY");
674         break;
675
676     case DDERR_PRIMARYSURFACEALREADYEXISTS: 
677         // This process has already created a primary surface. 
678         lpszError = TEXT("DDERR_PRIMARYSURFACEALREADYEXISTS");
679         break;
680
681     case DDERR_REGIONTOOSMALL: 
682         // The region passed to the 
683         // IDirectDrawClipper::GetClipList method is too small. 
684         lpszError = TEXT("DDERR_REGIONTOOSMALL");
685         break;
686
687     case DDERR_SURFACEALREADYATTACHED: 
688         // An attempt was made to attach a surface to 
689         // another surface to which it is already attached. 
690         lpszError = TEXT("DDERR_SURFACEALREADYATTACHED");
691         break;
692
693     case DDERR_SURFACEALREADYDEPENDENT: 
694         // An attempt was made to make a surface a dependency 
695         // of another surface to which it is already dependent. 
696         lpszError = TEXT("DDERR_SURFACEALREADYDEPENDENT");
697         break;
698
699     case DDERR_SURFACEBUSY: 
700         // Access to the surface is refused because the 
701         // surface is locked by another thread. 
702         lpszError = TEXT("DDERR_SURFACEBUSY");
703         break;
704
705     case DDERR_SURFACEISOBSCURED: 
706         // Access to the surface is refused 
707         // because the surface is obscured. 
708         lpszError = TEXT("DDERR_SURFACEISOBSCURED");
709         break;
710
711     case DDERR_SURFACELOST: 
712         // Access to the surface is refused because the 
713         // surface memory is gone. The DirectDrawSurface 
714         // object representing this surface should have 
715         // the IDirectDrawSurface4::Restore method called on it. 
716         lpszError = TEXT("DDERR_SURFACELOST");
717         break;
718
719     case DDERR_SURFACENOTATTACHED: 
720         // The requested surface is not attached. 
721         lpszError = TEXT("DDERR_SURFACENOTATTACHED");
722         break;
723
724     case DDERR_TOOBIGHEIGHT: 
725         // The height requested by DirectDraw is too large. 
726         lpszError = TEXT("DDERR_TOOBIGHEIGHT");
727         break;
728
729     case DDERR_TOOBIGSIZE: 
730         // The size requested by DirectDraw is too large. 
731         // However, the individual height and width are OK.
732         lpszError = TEXT("DDERR_TOOBIGSIZE");
733         break;
734
735     case DDERR_TOOBIGWIDTH: 
736         // The width requested by DirectDraw is too large. 
737         lpszError = TEXT("DDERR_TOOBIGWIDTH");
738         break;
739
740     case DDERR_UNSUPPORTED: 
741         // The operation is not supported. 
742         lpszError = TEXT("DDERR_UNSUPPORTED");
743         break;
744
745     case DDERR_UNSUPPORTEDFORMAT: 
746         // The FourCC format requested is not supported by DirectDraw. 
747         lpszError = TEXT("DDERR_UNSUPPORTEDFORMAT");
748         break;
749
750     case DDERR_UNSUPPORTEDMASK: 
751         // The bitmask in the pixel format requested is not supported by DirectDraw. 
752         lpszError = TEXT("DDERR_UNSUPPORTEDMASK");
753         break;
754
755     case DDERR_UNSUPPORTEDMODE: 
756         // The display is currently in an unsupported mode. 
757         lpszError = TEXT("DDERR_UNSUPPORTEDMODE");
758         break;
759
760     case DDERR_VERTICALBLANKINPROGRESS: 
761         // A vertical blank is in progress. 
762         lpszError = TEXT("DDERR_VERTICALBLANKINPROGRESS");
763         break;
764
765     case DDERR_WASSTILLDRAWING: 
766         // The previous blit operation that is transferring 
767         // information to or from this surface is incomplete. 
768         lpszError = TEXT("DDERR_WASSTILLDRAWING");
769         break;
770
771     case DDERR_WRONGMODE:
772         // This surface cannot be restored because it was created in a different mode. 
773         lpszError = TEXT("DDERR_WRONGMODE");
774         break;
775
776     case DDERR_XALIGN:
777         // The provided rectangle was not horizontally aligned on a required boundary. 
778         lpszError = TEXT("DDERR_XALIGN");
779         break;
780
781     case DDERR_VIDEONOTACTIVE:
782         // The video port is not active
783         lpszError = TEXT("DDERR_VIDEONOTACTIVE");
784         break;
785
786
787         //
788         // D3D Immediate Mode Errors
789         //
790
791     case D3DERR_BADMAJORVERSION:
792         // ???
793         lpszError = TEXT("D3DERR_BADMAJORVERSION");
794         break;
795
796     case D3DERR_BADMINORVERSION:
797         // ???
798         lpszError = TEXT("D3DERR_BADMINORVERSION");
799         break;
800
801     case D3DERR_INVALID_DEVICE:
802         // ???
803         lpszError = TEXT("D3DERR_INVALID_DEVICE");
804         break;
805
806     case D3DERR_INITFAILED:
807         // ???
808         lpszError = TEXT("D3DERR_INITFAILED");
809         break;
810
811     case D3DERR_EXECUTE_CREATE_FAILED:
812         // ???
813         lpszError = TEXT("D3DERR_EXECUTE_CREATE_FAILED");
814         break;
815
816     case D3DERR_EXECUTE_DESTROY_FAILED:
817         // ???
818         lpszError = TEXT("D3DERR_EXECUTE_DESTROY_FAILED");
819         break;
820
821     case D3DERR_EXECUTE_LOCK_FAILED:
822         // ???
823         lpszError = TEXT("D3DERR_EXECUTE_LOCK_FAILED");
824         break;
825
826     case D3DERR_EXECUTE_UNLOCK_FAILED:
827         // ???
828         lpszError = TEXT("D3DERR_EXECUTE_UNLOCK_FAILED");
829         break;
830
831     case D3DERR_EXECUTE_LOCKED:
832         // ???
833         lpszError = TEXT("D3DERR_EXECUTE_LOCKED");
834         break;
835
836     case D3DERR_EXECUTE_NOT_LOCKED:
837         // ???
838         lpszError = TEXT("D3DERR_EXECUTE_NOT_LOCKED");
839         break;
840
841     case D3DERR_EXECUTE_FAILED:
842         // ???
843         lpszError = TEXT("D3DERR_EXECUTE_FAILED");
844         break;
845
846     case D3DERR_EXECUTE_CLIPPED_FAILED:
847         // ???
848         lpszError = TEXT("D3DERR_CLIPPED_FAILED");
849         break;
850
851     case D3DERR_TEXTURE_NO_SUPPORT:
852         // ???
853         lpszError = TEXT("D3DERR_TEXTURE_NO_SUPPORT");
854         break;
855
856     case D3DERR_TEXTURE_CREATE_FAILED:
857         // ???
858         lpszError = TEXT("D3DERR_TEXTURE_CREATE_FAILED");
859         break;
860
861     case D3DERR_TEXTURE_DESTROY_FAILED:
862         // ???
863         lpszError = TEXT("D3DERR_TEXTURE_DESTROY_FAILED");
864         break;
865
866     case D3DERR_TEXTURE_LOCK_FAILED:
867         // ???
868         lpszError = TEXT("D3DERR_TEXTURE_LOCK_FAILED");
869         break;
870
871     case D3DERR_TEXTURE_UNLOCK_FAILED:
872         // ???
873         lpszError = TEXT("D3DERR_TEXTURE_UNLOCK_FAILED");
874         break;
875
876     case D3DERR_TEXTURE_LOAD_FAILED:
877         // ???
878         lpszError = TEXT("D3DERR_LOAD_FAILED");
879         break;
880
881     case D3DERR_TEXTURE_SWAP_FAILED:
882         // ???
883         lpszError = TEXT("D3DERR_SWAP_FAILED");
884         break;
885
886     case D3DERR_TEXTURE_LOCKED:
887         // ???
888         lpszError = TEXT("D3DERR_TEXTURE_LOCKED");
889         break;
890
891     case D3DERR_TEXTURE_NOT_LOCKED:
892         // ???
893         lpszError = TEXT("D3DERR_TEXTURE_NOT_LOCKED");
894         break;
895
896     case D3DERR_TEXTURE_GETSURF_FAILED:
897         // ???
898         lpszError = TEXT("D3DERR_TEXTURE_GETSURF_FAILED");
899         break;
900
901     case D3DERR_MATRIX_CREATE_FAILED:
902         // ???
903         lpszError = TEXT("D3DERR_MATRIX_CREATE_FAILED");
904         break;
905
906     case D3DERR_MATRIX_DESTROY_FAILED:
907         // ???
908         lpszError = TEXT("D3DERR_MATRIX_DESTROY_FAILED");
909         break;
910
911     case D3DERR_MATRIX_SETDATA_FAILED:
912         // ???
913         lpszError = TEXT("D3DERR_MATRIX_SETDATA_FAILED");
914         break;
915
916     case D3DERR_MATRIX_GETDATA_FAILED:
917         // ???
918         lpszError = TEXT("D3DERR_MAXTRIX_GETDATA_FAILED");
919         break;
920
921     case D3DERR_SETVIEWPORTDATA_FAILED:
922         // ???
923         lpszError = TEXT("D3DERR_SETVIEWPORTDATA_FAILED");
924         break;
925
926     case D3DERR_INVALIDCURRENTVIEWPORT:
927         // ???
928         lpszError = TEXT("D3DERR_INVALIDCURRENTVIEWPORT");
929         break;
930         
931     case D3DERR_INVALIDPRIMITIVETYPE:
932         // ???
933         lpszError = TEXT("D3DERR_INVALIDPRIMITIVETYPE");
934         break;
935
936     case D3DERR_INVALIDVERTEXTYPE:
937         // ???
938         lpszError = TEXT("D3DERR_INVALIDVERTEXTYPE");
939         break;
940
941     case D3DERR_TEXTURE_BADSIZE:
942         // ???
943         lpszError = TEXT("D3DERR_TEXTURE_BADSIZE");
944         break;
945
946     case D3DERR_MATERIAL_CREATE_FAILED:
947         // ???
948         lpszError = TEXT("D3DERR_MATERIAL_CREATE_FAILED");
949         break;
950
951     case D3DERR_MATERIAL_DESTROY_FAILED:
952         // ???
953         lpszError = TEXT("D3DERR_MATERIAL_DESTROY_FAILED");
954         break;
955
956     case D3DERR_MATERIAL_SETDATA_FAILED:
957         // ???
958         lpszError = TEXT("D3DERR_MATERIAL_SETDATA_FAILED");
959         break;
960
961     case D3DERR_MATERIAL_GETDATA_FAILED:
962         // ???
963         lpszError = TEXT("D3DERR_MATERIAL_GETDATA_FAILED");
964         break;
965
966     case D3DERR_INVALIDPALETTE:
967         // ???
968         lpszError = TEXT("D3DERR_INVALIDPALETTE");
969         break;
970
971     case D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY:
972         // ???
973         lpszError = TEXT("D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY");
974         break;
975
976     case D3DERR_ZBUFF_NEEDS_VIDEOMEMORY:
977         // ???
978         lpszError = TEXT("D3DERR_ZBUFF_NEEDS_VIDEOMEMORY");
979         break;
980
981     case D3DERR_SURFACENOTINVIDMEM:
982         // ???
983         lpszError = TEXT("D3DERR_SURFACENOTINVIDMEM");
984         break;
985
986     case D3DERR_LIGHT_SET_FAILED:
987         // ???
988         lpszError = TEXT("D3DERR_LIGHT_SET_FAILED");
989         break;
990
991     case D3DERR_LIGHTHASVIEWPORT:
992         // ???
993         lpszError = TEXT("D3DERR_LIGHTHASVIEWPORT");
994         break;
995
996     case D3DERR_LIGHTNOTINTHISVIEWPORT:
997         // ???
998         lpszError = TEXT("D3DERR_LIGHTNOTINTHISVIEWPORT");
999         break;
1000
1001     case D3DERR_SCENE_IN_SCENE:
1002         // ???
1003         lpszError = TEXT("D3DERR_SCENE_IN_SCENE");
1004         break;
1005
1006     case D3DERR_SCENE_NOT_IN_SCENE:
1007         // ???
1008         lpszError = TEXT("D3DERR_SCENE_NOT_IN_SCENE");
1009         break;
1010
1011     case D3DERR_SCENE_BEGIN_FAILED:
1012         // ???
1013         lpszError = TEXT("D3DERR_SCENE_BEGIN_FAILED");
1014         break;
1015
1016     case D3DERR_SCENE_END_FAILED:
1017         // ???
1018         lpszError = TEXT("D3DERR_SCENE_END_FAILED");
1019         break;
1020
1021     case D3DERR_INBEGIN:
1022         // ???
1023         lpszError = TEXT("D3DERR_INBEGIN");
1024         break;
1025
1026     case D3DERR_NOTINBEGIN:
1027         // ???
1028         lpszError = TEXT("D3DERR_NOTINBEGIN");
1029         break;
1030
1031     case D3DERR_NOVIEWPORTS:
1032         // ???
1033         lpszError = TEXT("D3DERR_NOVIEWPORTS");
1034         break;
1035
1036     case D3DERR_VIEWPORTDATANOTSET:
1037         // ???
1038         lpszError = TEXT("D3DERR_VIEWPORTDATANOTSET");
1039         break;
1040
1041     case D3DERR_VIEWPORTHASNODEVICE:
1042         // ???
1043         lpszError = TEXT("D3DERR_VIEWPORTHASNODEVICE");
1044         break;
1045
1046     
1047         //
1048         // D3D Retained Mode Errors
1049         //
1050 #if 0    
1051     case D3DRMERR_BADOBJECT:
1052         // ???
1053         lpszError = TEXT("D3DRMERR_BADOBJECT");
1054         break;
1055
1056     case D3DRMERR_BADTYPE:
1057         // ???
1058         lpszError = TEXT("D3DRMERR_BADTYPE");
1059         break;
1060
1061     case D3DRMERR_BADALLOC:
1062         // ???
1063         lpszError = TEXT("D3DRMERR_BADALLOC");
1064         break;
1065
1066     case D3DRMERR_FACEUSED:
1067         // ???
1068         lpszError = TEXT("D3DRMERR_FACEUSED");
1069         break;
1070
1071     case D3DRMERR_NOTFOUND:
1072         // ???
1073         lpszError = TEXT("D3DRMERR_NOTFOUND");
1074         break;
1075
1076     case D3DRMERR_NOTDONEYET:
1077         // ???
1078         lpszError = TEXT("D3DRMERR_NOTDONEYET");
1079         break;
1080
1081     case D3DRMERR_FILENOTFOUND:
1082         // ???
1083         lpszError = TEXT("D3DRMERR_FILENOTFOUND");
1084         break;
1085
1086     case D3DRMERR_BADFILE:
1087         // ???
1088         lpszError = TEXT("D3DRMERR_BADFILE");
1089         break;
1090
1091     case D3DRMERR_BADDEVICE:
1092         // ???
1093         lpszError = TEXT("D3DRMERR_BADDEVICE");
1094         break;
1095
1096     case D3DRMERR_BADVALUE:
1097         // ???
1098         lpszError = TEXT("D3DRMERR_BADVALUE");
1099         break;
1100
1101     case D3DRMERR_BADMAJORVERSION:
1102         // ???
1103         lpszError = TEXT("D3DRMERR_BADMAJORVERSION");
1104         break;
1105
1106     case D3DRMERR_BADMINORVERSION:
1107         // ???
1108         lpszError = TEXT("D3DRMERR_BADMINORVERSION");
1109         break;
1110
1111     case D3DRMERR_UNABLETOEXECUTE:
1112         // ???
1113         lpszError = TEXT("D3DRMERR_BADMINORVERSION");
1114         break;
1115 #endif // D3DRM_ERRORS
1116
1117
1118                 //
1119                 // Application defined errors
1120                 //
1121         case APPERR_GENERIC:
1122         // Generic Error
1123         lpszError = TEXT("APPERR_GENERIC");
1124         break;
1125
1126         case APPERR_INVALIDPARAMS:
1127         // Invalid Parameters passed into function
1128         lpszError = TEXT("APPERR_INVALIDPARAMS");
1129         break;
1130
1131         case APPERR_NOTINITIALIZED:
1132                 // Programmer error, called function without proper initialization
1133                 lpszError = TEXT("APPERR_NOT_INITIALIZED");
1134                 break;
1135
1136     default:
1137         // Unknown DD/D3D/App Error
1138         wsprintf (szMsg, "Unknown Error #%ld", (DWORD)(hResult & 0x0000FFFFL));
1139         lpszError = szMsg;
1140         break;
1141     }
1142
1143     // Copy DD/D3D Error string to buff
1144     cLen = strlen (lpszError);
1145     if (cLen >= cchError)
1146     {
1147         cLen = cchError - 1;
1148     }
1149
1150     if (cLen)
1151     {
1152         strncpy (lpszErrorBuff, lpszError, cLen);
1153         lpszErrorBuff[cLen] = 0;
1154     }
1155
1156     return TRUE;
1157 } // End GetDDErrorString
1158
1159
1160
1161
1162 /*
1163 **-----------------------------------------------------------------------------
1164 ** End of File
1165 **-----------------------------------------------------------------------------
1166 */
1167
1168