0001: //-----------------------------------------------------------------------------
0002: // File: DXUtil.h
0003: //
0004: // Desc: Helper functions and typing shortcuts for DirectX programming.
0005: //-----------------------------------------------------------------------------
0006: #ifndef DXUTIL_H
0007: #define DXUTIL_H
0008: 
0009: 
0010: //-----------------------------------------------------------------------------
0011: // Miscellaneous helper functions
0012: //-----------------------------------------------------------------------------
0013: #define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
0014: #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
0015: #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
0016: 
0017: 
0018: 
0019: 
0020: //-----------------------------------------------------------------------------
0021: // Name: DXUtil_GetDXSDKMediaPath() and DXUtil_FindMediaFile() 
0022: // Desc: Returns the DirectX SDK path, as stored in the system registry
0023: //       during the SDK install.
0024: //-----------------------------------------------------------------------------
0025: const TCHAR* DXUtil_GetDXSDKMediaPath();
0026: HRESULT      DXUtil_FindMediaFile( TCHAR* strPath, TCHAR* strFilename );
0027: 
0028: 
0029: 
0030: 
0031: //-----------------------------------------------------------------------------
0032: // Name: DXUtil_Read*RegKey() and DXUtil_Write*RegKey()
0033: // Desc: Helper functions to read/write a string registry key 
0034: //-----------------------------------------------------------------------------
0035: HRESULT DXUtil_WriteStringRegKey( HKEY hKey, TCHAR* strRegName, TCHAR* strValue );
0036: HRESULT DXUtil_WriteIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD dwValue );
0037: HRESULT DXUtil_WriteGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID guidValue );
0038: HRESULT DXUtil_WriteBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL bValue );
0039: 
0040: HRESULT DXUtil_ReadStringRegKey( HKEY hKey, TCHAR* strRegName, TCHAR* strValue, DWORD dwLength, TCHAR* strDefault );
0041: HRESULT DXUtil_ReadIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD* pdwValue, DWORD dwDefault );
0042: HRESULT DXUtil_ReadGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID* pGuidValue, GUID& guidDefault );
0043: HRESULT DXUtil_ReadBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL* pbValue, BOOL bDefault );
0044: 
0045: 
0046: 
0047: 
0048: //-----------------------------------------------------------------------------
0049: // Name: DXUtil_Timer()
0050: // Desc: Performs timer opertations. Use the following commands:
0051: //          TIMER_RESET           - to reset the timer
0052: //          TIMER_START           - to start the timer
0053: //          TIMER_STOP            - to stop (or pause) the timer
0054: //          TIMER_ADVANCE         - to advance the timer by 0.1 seconds
0055: //          TIMER_GETABSOLUTETIME - to get the absolute system time
0056: //          TIMER_GETAPPTIME      - to get the current time
0057: //          TIMER_GETELAPSEDTIME  - to get the time that elapsed between 
0058: //                                  TIMER_GETELAPSEDTIME calls
0059: //-----------------------------------------------------------------------------
0060: enum TIMER_COMMAND { TIMER_RESET, TIMER_START, TIMER_STOP, TIMER_ADVANCE,
0061:                      TIMER_GETABSOLUTETIME, TIMER_GETAPPTIME, TIMER_GETELAPSEDTIME };
0062: FLOAT __stdcall DXUtil_Timer( TIMER_COMMAND command );
0063: 
0064: 
0065: 
0066: 
0067: //-----------------------------------------------------------------------------
0068: // UNICODE support for converting between CHAR, TCHAR, and WCHAR strings
0069: //-----------------------------------------------------------------------------
0070: VOID DXUtil_ConvertAnsiStringToWide( WCHAR* wstrDestination, const CHAR* strSource, int cchDestChar = -1 );
0071: VOID DXUtil_ConvertWideStringToAnsi( CHAR* strDestination, const WCHAR* wstrSource, int cchDestChar = -1 );
0072: VOID DXUtil_ConvertGenericStringToAnsi( CHAR* strDestination, const TCHAR* tstrSource, int cchDestChar = -1 );
0073: VOID DXUtil_ConvertGenericStringToWide( WCHAR* wstrDestination, const TCHAR* tstrSource, int cchDestChar = -1 );
0074: VOID DXUtil_ConvertAnsiStringToGeneric( TCHAR* tstrDestination, const CHAR* strSource, int cchDestChar = -1 );
0075: VOID DXUtil_ConvertWideStringToGeneric( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar = -1 );
0076: 
0077: 
0078: 
0079: 
0080: //-----------------------------------------------------------------------------
0081: // GUID to String converting 
0082: //-----------------------------------------------------------------------------
0083: VOID DXUtil_ConvertGUIDToString( const GUID* pGuidIn, TCHAR* strOut );
0084: BOOL DXUtil_ConvertStringToGUID( const TCHAR* strIn, GUID* pGuidOut );
0085: 
0086: 
0087: 
0088: 
0089: //-----------------------------------------------------------------------------
0090: // Debug printing support
0091: //-----------------------------------------------------------------------------
0092: VOID    DXUtil_Trace( TCHAR* strMsg, ... );
0093: HRESULT _DbgOut( TCHAR*, DWORD, HRESULT, TCHAR* );
0094: 
0095: #if defined(DEBUG) | defined(_DEBUG)
0096:     #define DXTRACE           DXUtil_Trace
0097: #else
0098:     #define DXTRACE           sizeof
0099: #endif
0100: 
0101: #if defined(DEBUG) | defined(_DEBUG)
0102:     #define DEBUG_MSG(str)    _DbgOut( __FILE__, (DWORD)__LINE__, 0, str )
0103: #else
0104:     #define DEBUG_MSG(str)    (0L)
0105: #endif
0106: 
0107: 
0108: 
0109: 
0110: #endif // DXUTIL_H
0111: