home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Extras / Sensaura / SDK1.0 / data1.cab / Example_Files / ZFXCons / directx.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-13  |  4.3 KB  |  131 lines

  1. /*
  2.     Company:            Sensaura Ltd
  3.     Copyright:          (C) 2000
  4.  
  5.     File Name:            directx.cpp
  6.     File Description:    Source file for implementation of DirectX macros and error handling 
  7.                         functions used by other application modules
  8.     Author:                Adam Philp
  9.     Last Update:        19-JAN-00
  10.  
  11.     Target Compiler:    Microsoft Visual C++ Version 5.0
  12. */
  13.  
  14. ///////////////////////    Included files ////////////////////////////////////////////////////////////
  15.  
  16. //#define __PCH    "stdafx.h"                // Precompiled header for MFC applications
  17. #define __PCH    <windows.h>                // Precompiled header for non-MFC applications
  18.  
  19. #include __PCH
  20.  
  21. #include <dsound.h>                        // DirectSound error codes
  22. #include "zoomfx.h"                        // Included here to register ZoomFX GUID
  23. #include "directx.h"                    // Function and macro declarations
  24.  
  25. #ifndef _MFC_VER                        // Use MFC TRACE macro if available
  26. #include "debug.h"                        // Use our own error handlers otherwise
  27. #endif
  28.  
  29. /////////////////////// Global constants //////////////////////////////////////////////////////////
  30.  
  31. const char* g_strDSError    = "DirectSound";
  32.  
  33. /////////////////////// Global variables //////////////////////////////////////////////////////////
  34.  
  35. HRESULT g_hrDS                = DS_OK;
  36. bool    g_bReportDXErrors    = true;        // Set to false to disable message boxes
  37.  
  38. /////////////////////// Local functions ///////////////////////////////////////////////////////////
  39.  
  40. /*
  41.     Function:            DirectXErrorToString
  42.     Description:        Translates a DirectX HRESULT value into a meaningful string which can be
  43.                         used for message boxes, debugging messages etc.
  44.     Parameters:            hrError - the HRESULT value to translate
  45.     Return value:        Pointer to the translated string
  46. */
  47.  
  48. const char* DirectXErrorToString(HRESULT hrError)
  49. {
  50.     switch(hrError)
  51.     {
  52.     case DSERR_ALLOCATED:                // DirectSound errors
  53.         return "DSERR_ALLOCATED\0";
  54.     case DSERR_ALREADYINITIALIZED: 
  55.         return "DSERR_ALREADYINITIALIZED\0";
  56.     case DSERR_BADFORMAT: 
  57.         return "DSERR_BADFORMAT\0";
  58.     case DSERR_BUFFERLOST: 
  59.         return "DSERR_BUFFERLOST\0";
  60.     case DSERR_CONTROLUNAVAIL: 
  61.         return "DSERR_CONTROLUNAVAIL\0";
  62.     case DSERR_INVALIDCALL: 
  63.         return "DSERR_INVALIDCALL\0";
  64.     case DSERR_NOAGGREGATION: 
  65.         return "DSERR_NOAGGREGATION\0";
  66.     case DSERR_NODRIVER:
  67.         return "DSERR_NODRIVER\0";
  68.     case DSERR_NOINTERFACE: 
  69.         return "DSERR_NOINTERFACE\0";
  70.     case DSERR_OTHERAPPHASPRIO: 
  71.         return "DSERR_OTHERAPPHASPRIO\0";
  72.     case DSERR_PRIOLEVELNEEDED: 
  73.         return "DSERR_PRIOLEVELNEEDED\0";
  74.     case DSERR_UNINITIALIZED: 
  75.         return "DSERR_UNINITIALIZED\0";
  76.  
  77.     default:                            // Only handle DirectSound errors in this app
  78.         return NULL;
  79.     }
  80. }
  81.  
  82. /////////////////////// Global functions //////////////////////////////////////////////////////////
  83.  
  84. /*
  85.     Function:            ReportDirectXError
  86.     Description:        Display a message box and/or TRACE message describing a DirectX error code
  87.     Parameters:            strErrorType - DirectX error type string for message box caption
  88.                         hrError - the HRESULT value to translate
  89.                         pFile - filename string
  90.                         line - line number where the error occurred
  91. */
  92.  
  93. void ReportDirectXError(LPCSTR strErrorType, HRESULT* phrError, LPCSTR pFile, int line)
  94. {
  95.     char        str[255];
  96.     const char* strError;
  97.     const char* strMessage;
  98.                                         // Convert DirectX error code into a meaningful string
  99.     strError = DirectXErrorToString(*phrError);
  100.     if(strError)                        // Did we recognize this error code?
  101.         strMessage = strError;            // Yes, so display the string
  102.     else 
  103.     {                                    // No, so display the error code
  104.         wsprintf(str, "Unrecognized error code: %08X", *phrError);
  105.         strMessage = str;
  106.     }
  107. #ifdef _DXTRACE                            // Output the error message as a debug string 
  108.     if(pFile && line)                    // We know the module filename and line number
  109.     {
  110. #ifdef _MFC_VER
  111.         TRACE("%s Error in %s @line #%d: %s\n", strErrorType, pFile, line, strMessage);
  112. #else
  113.         TRACE(-1, "%s Error in %s @line #%d: %s\n", strErrorType, pFile, line, strMessage);
  114. #endif
  115.     }
  116.     else
  117.     {
  118. #ifdef _MFC_VER
  119.         TRACE("%s Error: %s\n", strErrorType, strMessage);
  120. #else
  121.         TRACE(-1, "%s Error: %s\n", strErrorType, strMessage);
  122. #endif
  123.     }
  124. #endif
  125.     if(g_bReportDXErrors)
  126.     {
  127.         MessageBox(NULL, strMessage, strErrorType, MB_ICONEXCLAMATION|MB_OK);
  128.         *phrError = 0;                    // Clear the error code if we have displayed a message box
  129.     }
  130. }
  131.