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: #ifndef UNDER_CE
0019: //-----------------------------------------------------------------------------
0020: // Name: DXUtil_GetDXSDKMediaPath() and DXUtil_FindMediaFile() 
0021: // Desc: Returns the DirectX SDK path, as stored in the system registry
0022: //       during the SDK install.
0023: //-----------------------------------------------------------------------------
0024: HRESULT DXUtil_GetDXSDKMediaPathCch( TCHAR* strDest, int cchDest );
0025: HRESULT DXUtil_GetDXSDKMediaPathCb( TCHAR* szDest, int cbDest );
0026: HRESULT DXUtil_FindMediaFileCch( TCHAR* strDestPath, int cchDest, TCHAR* strFilename );
0027: HRESULT DXUtil_FindMediaFileCb( TCHAR* szDestPath, int cbDest, TCHAR* strFilename );
0028: #endif // !UNDER_CE
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_ReadStringRegKeyCch( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, DWORD cchDest, TCHAR* strDefault );
0041: HRESULT DXUtil_ReadStringRegKeyCb( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, DWORD cbDest, TCHAR* strDefault );
0042: HRESULT DXUtil_ReadIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD* pdwValue, DWORD dwDefault );
0043: HRESULT DXUtil_ReadGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID* pGuidValue, GUID& guidDefault );
0044: HRESULT DXUtil_ReadBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL* pbValue, BOOL bDefault );
0045: 
0046: 
0047: //-----------------------------------------------------------------------------
0048: // Name: DXUtil_Timer()
0049: // Desc: Performs timer opertations. Use the following commands:
0050: //          TIMER_RESET           - to reset the timer
0051: //          TIMER_START           - to start the timer
0052: //          TIMER_STOP            - to stop (or pause) the timer
0053: //          TIMER_ADVANCE         - to advance the timer by 0.1 seconds
0054: //          TIMER_GETABSOLUTETIME - to get the absolute system time
0055: //          TIMER_GETAPPTIME      - to get the current time
0056: //          TIMER_GETELAPSEDTIME  - to get the time that elapsed between 
0057: //                                  TIMER_GETELAPSEDTIME calls
0058: //-----------------------------------------------------------------------------
0059: enum TIMER_COMMAND { TIMER_RESET, TIMER_START, TIMER_STOP, TIMER_ADVANCE,
0060:                      TIMER_GETABSOLUTETIME, TIMER_GETAPPTIME, TIMER_GETELAPSEDTIME };
0061: FLOAT __stdcall DXUtil_Timer( TIMER_COMMAND command );
0062: 
0063: 
0064: //-----------------------------------------------------------------------------
0065: // UNICODE support for converting between CHAR, TCHAR, and WCHAR strings
0066: //-----------------------------------------------------------------------------
0067: HRESULT DXUtil_ConvertAnsiStringToWideCch( WCHAR* wstrDestination, const CHAR* strSource, int cchDestChar );
0068: HRESULT DXUtil_ConvertWideStringToAnsiCch( CHAR* strDestination, const WCHAR* wstrSource, int cchDestChar );
0069: HRESULT DXUtil_ConvertGenericStringToAnsiCch( CHAR* strDestination, const TCHAR* tstrSource, int cchDestChar );
0070: HRESULT DXUtil_ConvertGenericStringToWideCch( WCHAR* wstrDestination, const TCHAR* tstrSource, int cchDestChar );
0071: HRESULT DXUtil_ConvertAnsiStringToGenericCch( TCHAR* tstrDestination, const CHAR* strSource, int cchDestChar );
0072: HRESULT DXUtil_ConvertWideStringToGenericCch( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar );
0073: HRESULT DXUtil_ConvertAnsiStringToWideCb( WCHAR* wstrDestination, const CHAR* strSource, int cbDestChar );
0074: HRESULT DXUtil_ConvertWideStringToAnsiCb( CHAR* strDestination, const WCHAR* wstrSource, int cbDestChar );
0075: HRESULT DXUtil_ConvertGenericStringToAnsiCb( CHAR* strDestination, const TCHAR* tstrSource, int cbDestChar );
0076: HRESULT DXUtil_ConvertGenericStringToWideCb( WCHAR* wstrDestination, const TCHAR* tstrSource, int cbDestChar );
0077: HRESULT DXUtil_ConvertAnsiStringToGenericCb( TCHAR* tstrDestination, const CHAR* strSource, int cbDestChar );
0078: HRESULT DXUtil_ConvertWideStringToGenericCb( TCHAR* tstrDestination, const WCHAR* wstrSource, int cbDestChar );
0079: 
0080: 
0081: //-----------------------------------------------------------------------------
0082: // Readme functions
0083: //-----------------------------------------------------------------------------
0084: VOID DXUtil_LaunchReadme( HWND hWnd, TCHAR* strLoc = NULL );
0085: 
0086: //-----------------------------------------------------------------------------
0087: // GUID to String converting 
0088: //-----------------------------------------------------------------------------
0089: HRESULT DXUtil_ConvertGUIDToStringCch( const GUID* pGuidSrc, TCHAR* strDest, int cchDestChar );
0090: HRESULT DXUtil_ConvertGUIDToStringCb( const GUID* pGuidSrc, TCHAR* strDest, int cbDestChar );
0091: HRESULT DXUtil_ConvertStringToGUID( const TCHAR* strIn, GUID* pGuidOut );
0092: 
0093: 
0094: //-----------------------------------------------------------------------------
0095: // Debug printing support
0096: // See dxerr9.h for more debug printing support
0097: //-----------------------------------------------------------------------------
0098: VOID    DXUtil_Trace( TCHAR* strMsg, ... );
0099: 
0100: #if defined(DEBUG) | defined(_DEBUG)
0101:     #define DXTRACE           DXUtil_Trace
0102: #else
0103:     #define DXTRACE           sizeof
0104: #endif
0105: 
0106: 
0107: //-----------------------------------------------------------------------------
0108: // Name: ArrayListType
0109: // Desc: Indicates how data should be stored in a CArrayList
0110: //-----------------------------------------------------------------------------
0111: enum ArrayListType
0112: {
0113:     AL_VALUE,       // entry data is copied into the list
0114:     AL_REFERENCE,   // entry pointers are copied into the list
0115: };
0116: 
0117: 
0118: //-----------------------------------------------------------------------------
0119: // Name: CArrayList
0120: // Desc: A growable array
0121: //-----------------------------------------------------------------------------
0122: class CArrayList
0123: {
0124: protected:
0125:     ArrayListType m_ArrayListType;
0126:     void* m_pData;
0127:     UINT m_BytesPerEntry;
0128:     UINT m_NumEntries;
0129:     UINT m_NumEntriesAllocated;
0130: 
0131: public:
0132:     CArrayList( ArrayListType Type, UINT BytesPerEntry = 0 );
0133:     ~CArrayList( void );
0134:     HRESULT Add( void* pEntry );
0135:     void Remove( UINT Entry );
0136:     void* GetPtr( UINT Entry );
0137:     UINT Count( void ) { return m_NumEntries; }
0138:     bool Contains( void* pEntryData );
0139:     void Clear( void ) { m_NumEntries = 0; }
0140: };
0141: 
0142: //-----------------------------------------------------------------------------
0143: // WinCE build support
0144: //-----------------------------------------------------------------------------
0145: 
0146: #ifdef UNDER_CE
0147: 
0148: #define CheckDlgButton(hdialog, id, state) ::SendMessage(::GetDlgItem(hdialog, id), BM_SETCHECK, state, 0)
0149: #define IsDlgButtonChecked(hdialog, id) ::SendMessage(::GetDlgItem(hdialog, id), BM_GETCHECK, 0L, 0L)
0150: #define GETTIMESTAMP GetTickCount
0151: #define _TWINCE(x) _T(x)
0152: 
0153: __inline int GetScrollPos(HWND hWnd, int nBar)
0154: {
0155:     SCROLLINFO si;
0156:     memset(&si, 0, sizeof(si));
0157:     si.cbSize = sizeof(si);
0158:     si.fMask = SIF_POS;
0159:     if (!GetScrollInfo(hWnd, nBar, &si))
0160:     {
0161:         return 0;
0162:     }
0163:     else
0164:     {
0165:         return si.nPos;
0166:     }
0167: }
0168: 
0169: #else // !UNDER_CE
0170: 
0171: #define GETTIMESTAMP timeGetTime
0172: #define _TWINCE(x) x
0173: 
0174: #endif // UNDER_CE
0175: 
0176: 
0177: #endif // DXUTIL_H
0178: