home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Extras / Sensaura / SDK1.0 / data1.cab / Example_Files / ZoomFX / directx.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-13  |  4.3 KB  |  132 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:        04-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.  
  23. #include "directx.h"                    // Function and macro declarations
  24. #include "zoomfx.h"                        // Must be included here to register ZoomFX GUID
  25.  
  26. #ifndef _MFC_VER                        // Use MFC TRACE macro if available
  27. #include "debug.h"                        // Use our own error handlers otherwise
  28. #endif
  29.  
  30. /////////////////////// Global constants //////////////////////////////////////////////////////////
  31.  
  32. const char* g_strDSError    = "DirectSound";
  33.  
  34. /////////////////////// Global variables //////////////////////////////////////////////////////////
  35.  
  36. HRESULT g_hrDS                = DS_OK;
  37. bool    g_bReportDXErrors    = true;        // Set to false to disable message boxes
  38.  
  39. /////////////////////// Local functions ///////////////////////////////////////////////////////////
  40.  
  41. /*
  42.     Function:            DirectXErrorToString
  43.     Description:        Translates a DirectX HRESULT value into a meaningful string which can be
  44.                         used for message boxes, debugging messages etc.
  45.     Parameters:            hrError - the HRESULT value to translate
  46.     Return value:        Pointer to the translated string
  47. */
  48.  
  49. const char* DirectXErrorToString(HRESULT hrError)
  50. {
  51.     switch(hrError)
  52.     {
  53.     case DSERR_ALLOCATED:                // DirectSound errors
  54.         return "DSERR_ALLOCATED\0";
  55.     case DSERR_ALREADYINITIALIZED: 
  56.         return "DSERR_ALREADYINITIALIZED\0";
  57.     case DSERR_BADFORMAT: 
  58.         return "DSERR_BADFORMAT\0";
  59.     case DSERR_BUFFERLOST: 
  60.         return "DSERR_BUFFERLOST\0";
  61.     case DSERR_CONTROLUNAVAIL: 
  62.         return "DSERR_CONTROLUNAVAIL\0";
  63.     case DSERR_INVALIDCALL: 
  64.         return "DSERR_INVALIDCALL\0";
  65.     case DSERR_NOAGGREGATION: 
  66.         return "DSERR_NOAGGREGATION\0";
  67.     case DSERR_NODRIVER:
  68.         return "DSERR_NODRIVER\0";
  69.     case DSERR_NOINTERFACE: 
  70.         return "DSERR_NOINTERFACE\0";
  71.     case DSERR_OTHERAPPHASPRIO: 
  72.         return "DSERR_OTHERAPPHASPRIO\0";
  73.     case DSERR_PRIOLEVELNEEDED: 
  74.         return "DSERR_PRIOLEVELNEEDED\0";
  75.     case DSERR_UNINITIALIZED: 
  76.         return "DSERR_UNINITIALIZED\0";
  77.  
  78.     default:                            // Only handle DirectSound errors in this app
  79.         return NULL;
  80.     }
  81. }
  82.  
  83. /////////////////////// Global functions //////////////////////////////////////////////////////////
  84.  
  85. /*
  86.     Function:            ReportDirectXError
  87.     Description:        Display a message box and/or TRACE message describing a DirectX error code
  88.     Parameters:            strErrorType - DirectX error type string for message box caption
  89.                         hrError - the HRESULT value to translate
  90.                         pFile - filename string
  91.                         line - line number where the error occurred
  92. */
  93.  
  94. void ReportDirectXError(LPCSTR strErrorType, HRESULT* phrError, LPCSTR pFile, int line)
  95. {
  96.     char        str[255];
  97.     const char* strError;
  98.     const char* strMessage;
  99.                                         // Convert DirectX error code into a meaningful string
  100.     strError = DirectXErrorToString(*phrError);
  101.     if(strError)                        // Did we recognize this error code?
  102.         strMessage = strError;            // Yes, so display the string
  103.     else 
  104.     {                                    // No, so display the error code
  105.         wsprintf(str, "Unrecognized error code: %08X", *phrError);
  106.         strMessage = str;
  107.     }
  108. #ifdef _DXTRACE                            // Output the error message as a debug string 
  109.     if(pFile && line)                    // We know the module filename and line number
  110.     {
  111. #ifdef _MFC_VER
  112.         TRACE("%s Error in %s @line #%d: %s\n", strErrorType, pFile, line, strMessage);
  113. #else
  114.         TRACE(-1, "%s Error in %s @line #%d: %s\n", strErrorType, pFile, line, strMessage);
  115. #endif
  116.     }
  117.     else
  118.     {
  119. #ifdef _MFC_VER
  120.         TRACE("%s Error: %s\n", strErrorType, strMessage);
  121. #else
  122.         TRACE(-1, "%s Error: %s\n", strErrorType, strMessage);
  123. #endif
  124.     }
  125. #endif
  126.     if(g_bReportDXErrors)
  127.     {
  128.         MessageBox(NULL, strMessage, strErrorType, MB_ICONEXCLAMATION|MB_OK);
  129.         *phrError = 0;                    // Clear the error code if we have displayed a message box
  130.     }
  131. }
  132.