home *** CD-ROM | disk | FTP | other *** search
- /*
- Company: Sensaura Ltd
- Copyright: (C) 2000
-
- File Name: directx.cpp
- File Description: Source file for implementation of DirectX macros and error handling
- functions used by other application modules
- Author: Adam Philp
- Last Update: 04-JAN-00
-
- Target Compiler: Microsoft Visual C++ Version 5.0
- */
-
- /////////////////////// Included files ////////////////////////////////////////////////////////////
-
- //#define __PCH "stdafx.h" // Precompiled header for MFC applications
- #define __PCH <windows.h> // Precompiled header for non-MFC applications
-
- #include __PCH
-
- #include <dsound.h> // DirectSound error codes
-
- #include "directx.h" // Function and macro declarations
- #include "zoomfx.h" // Must be included here to register ZoomFX GUID
-
- #ifndef _MFC_VER // Use MFC TRACE macro if available
- #include "debug.h" // Use our own error handlers otherwise
- #endif
-
- /////////////////////// Global constants //////////////////////////////////////////////////////////
-
- const char* g_strDSError = "DirectSound";
-
- /////////////////////// Global variables //////////////////////////////////////////////////////////
-
- HRESULT g_hrDS = DS_OK;
- bool g_bReportDXErrors = true; // Set to false to disable message boxes
-
- /////////////////////// Local functions ///////////////////////////////////////////////////////////
-
- /*
- Function: DirectXErrorToString
- Description: Translates a DirectX HRESULT value into a meaningful string which can be
- used for message boxes, debugging messages etc.
- Parameters: hrError - the HRESULT value to translate
- Return value: Pointer to the translated string
- */
-
- const char* DirectXErrorToString(HRESULT hrError)
- {
- switch(hrError)
- {
- case DSERR_ALLOCATED: // DirectSound errors
- return "DSERR_ALLOCATED\0";
- case DSERR_ALREADYINITIALIZED:
- return "DSERR_ALREADYINITIALIZED\0";
- case DSERR_BADFORMAT:
- return "DSERR_BADFORMAT\0";
- case DSERR_BUFFERLOST:
- return "DSERR_BUFFERLOST\0";
- case DSERR_CONTROLUNAVAIL:
- return "DSERR_CONTROLUNAVAIL\0";
- case DSERR_INVALIDCALL:
- return "DSERR_INVALIDCALL\0";
- case DSERR_NOAGGREGATION:
- return "DSERR_NOAGGREGATION\0";
- case DSERR_NODRIVER:
- return "DSERR_NODRIVER\0";
- case DSERR_NOINTERFACE:
- return "DSERR_NOINTERFACE\0";
- case DSERR_OTHERAPPHASPRIO:
- return "DSERR_OTHERAPPHASPRIO\0";
- case DSERR_PRIOLEVELNEEDED:
- return "DSERR_PRIOLEVELNEEDED\0";
- case DSERR_UNINITIALIZED:
- return "DSERR_UNINITIALIZED\0";
-
- default: // Only handle DirectSound errors in this app
- return NULL;
- }
- }
-
- /////////////////////// Global functions //////////////////////////////////////////////////////////
-
- /*
- Function: ReportDirectXError
- Description: Display a message box and/or TRACE message describing a DirectX error code
- Parameters: strErrorType - DirectX error type string for message box caption
- hrError - the HRESULT value to translate
- pFile - filename string
- line - line number where the error occurred
- */
-
- void ReportDirectXError(LPCSTR strErrorType, HRESULT* phrError, LPCSTR pFile, int line)
- {
- char str[255];
- const char* strError;
- const char* strMessage;
- // Convert DirectX error code into a meaningful string
- strError = DirectXErrorToString(*phrError);
- if(strError) // Did we recognize this error code?
- strMessage = strError; // Yes, so display the string
- else
- { // No, so display the error code
- wsprintf(str, "Unrecognized error code: %08X", *phrError);
- strMessage = str;
- }
- #ifdef _DXTRACE // Output the error message as a debug string
- if(pFile && line) // We know the module filename and line number
- {
- #ifdef _MFC_VER
- TRACE("%s Error in %s @line #%d: %s\n", strErrorType, pFile, line, strMessage);
- #else
- TRACE(-1, "%s Error in %s @line #%d: %s\n", strErrorType, pFile, line, strMessage);
- #endif
- }
- else
- {
- #ifdef _MFC_VER
- TRACE("%s Error: %s\n", strErrorType, strMessage);
- #else
- TRACE(-1, "%s Error: %s\n", strErrorType, strMessage);
- #endif
- }
- #endif
- if(g_bReportDXErrors)
- {
- MessageBox(NULL, strMessage, strErrorType, MB_ICONEXCLAMATION|MB_OK);
- *phrError = 0; // Clear the error code if we have displayed a message box
- }
- }
-