dxutil.cpp
上传用户:luhy168
上传日期:2022-01-10
资源大小:240k
文件大小:23k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. // File: DXUtil.cpp
  3. //
  4. // Desc: Shortcut macros and functions for using DX objects
  5. //
  6. //
  7. // Copyright (c) 1997-2001 Microsoft Corporation. All rights reserved
  8. //-----------------------------------------------------------------------------
  9. #define STRICT
  10. #include <windows.h>
  11. #include <mmsystem.h>
  12. #include <tchar.h>
  13. #include <stdio.h> 
  14. #include <stdarg.h>
  15. #include "DXUtil.h"
  16. //-----------------------------------------------------------------------------
  17. // Name: DXUtil_GetDXSDKMediaPath()
  18. // Desc: Returns the DirectX SDK media path
  19. //-----------------------------------------------------------------------------
  20. const TCHAR* DXUtil_GetDXSDKMediaPath()
  21. {
  22.     static TCHAR strNull[2] = _T("");
  23.     static TCHAR strPath[MAX_PATH];
  24.     DWORD dwType;
  25.     DWORD dwSize = MAX_PATH;
  26.     HKEY  hKey;
  27.     // Open the appropriate registry key
  28.     LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  29.                                 _T("Software\Microsoft\DirectX SDK"),
  30.                                 0, KEY_READ, &hKey );
  31.     if( ERROR_SUCCESS != lResult )
  32.         return strNull;
  33.     lResult = RegQueryValueEx( hKey, _T("DX81SDK Samples Path"), NULL,
  34.                               &dwType, (BYTE*)strPath, &dwSize );
  35.     RegCloseKey( hKey );
  36.     if( ERROR_SUCCESS != lResult )
  37.         return strNull;
  38.     _tcscat( strPath, _T("\Media\") );
  39.     return strPath;
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Name: DXUtil_FindMediaFile()
  43. // Desc: Returns a valid path to a DXSDK media file
  44. //-----------------------------------------------------------------------------
  45. HRESULT DXUtil_FindMediaFile( TCHAR* strPath, TCHAR* strFilename )
  46. {
  47.     HANDLE file;
  48.     TCHAR strFullPath[1024];
  49.     TCHAR *strShortName;
  50.     DWORD cchPath;
  51.     if( NULL==strFilename || NULL==strPath )
  52.         return E_INVALIDARG;
  53.     // Build full path name from strFileName (strShortName will be just the leaf filename)
  54.     cchPath = GetFullPathName(strFilename, sizeof(strFullPath)/sizeof(TCHAR), strFullPath, &strShortName);
  55.     if ((cchPath == 0) || (sizeof(strFullPath)/sizeof(TCHAR) <= cchPath))
  56.         return E_FAIL;
  57.     // first try to find the filename given a full path
  58.     file = CreateFile( strFullPath, GENERIC_READ, FILE_SHARE_READ, NULL, 
  59.                        OPEN_EXISTING, 0, NULL );
  60.     if( INVALID_HANDLE_VALUE != file )
  61.     {
  62.         _tcscpy( strPath, strFullPath );
  63.         CloseHandle( file );
  64.         return S_OK;
  65.     }
  66.     
  67.     // next try to find the filename in the current working directory (path stripped)
  68.     file = CreateFile( strShortName, GENERIC_READ, FILE_SHARE_READ, NULL, 
  69.                        OPEN_EXISTING, 0, NULL );
  70.     if( INVALID_HANDLE_VALUE != file )
  71.     {
  72.         _tcscpy( strPath, strShortName );
  73.         CloseHandle( file );
  74.         return S_OK;
  75.     }
  76.     
  77.     // last, check if the file exists in the media directory
  78.     _stprintf( strPath, _T("%s%s"), DXUtil_GetDXSDKMediaPath(), strShortName );
  79.     file = CreateFile( strPath, GENERIC_READ, FILE_SHARE_READ, NULL, 
  80.                        OPEN_EXISTING, 0, NULL );
  81.     if( INVALID_HANDLE_VALUE != file )
  82.     {
  83.         CloseHandle( file );
  84.         return S_OK;
  85.     }
  86.     // On failure, just return the file as the path
  87.     _tcscpy( strPath, strFilename );
  88.     return E_FAIL;
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Name: DXUtil_ReadStringRegKey()
  92. // Desc: Helper function to read a registry key string
  93. //-----------------------------------------------------------------------------
  94. HRESULT DXUtil_ReadStringRegKey( HKEY hKey, TCHAR* strRegName, TCHAR* strValue, 
  95.                                  DWORD dwLength, TCHAR* strDefault )
  96. {
  97.     DWORD dwType;
  98.     if( ERROR_SUCCESS != RegQueryValueEx( hKey, strRegName, 0, &dwType, 
  99.                                           (BYTE*)strValue, &dwLength ) )
  100.     {
  101.         _tcscpy( strValue, strDefault );
  102.     }
  103.     return S_OK;
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Name: DXUtil_WriteStringRegKey()
  107. // Desc: Helper function to write a registry key string
  108. //-----------------------------------------------------------------------------
  109. HRESULT DXUtil_WriteStringRegKey( HKEY hKey, TCHAR* strRegName,
  110.                                   TCHAR* strValue )
  111. {
  112.     if( ERROR_SUCCESS != RegSetValueEx( hKey, strRegName, 0, REG_SZ, 
  113.                                         (BYTE*)strValue, 
  114.                                         (_tcslen(strValue)+1)*sizeof(TCHAR) ) )
  115.         return E_FAIL;
  116.     return S_OK;
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Name: DXUtil_ReadIntRegKey()
  120. // Desc: Helper function to read a registry key int
  121. //-----------------------------------------------------------------------------
  122. HRESULT DXUtil_ReadIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD* pdwValue, 
  123.                               DWORD dwDefault )
  124. {
  125.     DWORD dwType;
  126.     DWORD dwLength = sizeof(DWORD);
  127.     if( ERROR_SUCCESS != RegQueryValueEx( hKey, strRegName, 0, &dwType, 
  128.                                           (BYTE*)pdwValue, &dwLength ) )
  129.     {
  130.         *pdwValue = dwDefault;
  131.     }
  132.     return S_OK;
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Name: DXUtil_WriteIntRegKey()
  136. // Desc: Helper function to write a registry key int
  137. //-----------------------------------------------------------------------------
  138. HRESULT DXUtil_WriteIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD dwValue )
  139. {
  140.     if( ERROR_SUCCESS != RegSetValueEx( hKey, strRegName, 0, REG_DWORD, 
  141.                                         (BYTE*)&dwValue, sizeof(DWORD) ) )
  142.         return E_FAIL;
  143.     return S_OK;
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Name: DXUtil_ReadBoolRegKey()
  147. // Desc: Helper function to read a registry key BOOL
  148. //-----------------------------------------------------------------------------
  149. HRESULT DXUtil_ReadBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL* pbValue, 
  150.                               BOOL bDefault )
  151. {
  152.     DWORD dwType;
  153.     DWORD dwLength = sizeof(BOOL);
  154.     if( ERROR_SUCCESS != RegQueryValueEx( hKey, strRegName, 0, &dwType, 
  155.                                           (BYTE*)pbValue, &dwLength ) )
  156.     {
  157.         *pbValue = bDefault;
  158.     }
  159.     return S_OK;
  160. }
  161. //-----------------------------------------------------------------------------
  162. // Name: DXUtil_WriteBoolRegKey()
  163. // Desc: Helper function to write a registry key BOOL
  164. //-----------------------------------------------------------------------------
  165. HRESULT DXUtil_WriteBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL bValue )
  166. {
  167.     if( ERROR_SUCCESS != RegSetValueEx( hKey, strRegName, 0, REG_DWORD, 
  168.                                         (BYTE*)&bValue, sizeof(BOOL) ) )
  169.         return E_FAIL;
  170.     return S_OK;
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Name: DXUtil_ReadGuidRegKey()
  174. // Desc: Helper function to read a registry key guid
  175. //-----------------------------------------------------------------------------
  176. HRESULT DXUtil_ReadGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID* pGuidValue, 
  177.                                GUID& guidDefault )
  178. {
  179.     DWORD dwType;
  180.     DWORD dwLength = sizeof(GUID);
  181.     if( ERROR_SUCCESS != RegQueryValueEx( hKey, strRegName, 0, &dwType, 
  182.                                           (LPBYTE) pGuidValue, &dwLength ) )
  183.     {
  184.         *pGuidValue = guidDefault;
  185.     }
  186.     return S_OK;
  187. }
  188. //-----------------------------------------------------------------------------
  189. // Name: DXUtil_WriteGuidRegKey()
  190. // Desc: Helper function to write a registry key guid
  191. //-----------------------------------------------------------------------------
  192. HRESULT DXUtil_WriteGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID guidValue )
  193. {
  194.     if( ERROR_SUCCESS != RegSetValueEx( hKey, strRegName, 0, REG_BINARY, 
  195.                                         (BYTE*)&guidValue, sizeof(GUID) ) )
  196.         return E_FAIL;
  197.     return S_OK;
  198. }
  199. //-----------------------------------------------------------------------------
  200. // Name: DXUtil_Timer()
  201. // Desc: Performs timer opertations. Use the following commands:
  202. //          TIMER_RESET           - to reset the timer
  203. //          TIMER_START           - to start the timer
  204. //          TIMER_STOP            - to stop (or pause) the timer
  205. //          TIMER_ADVANCE         - to advance the timer by 0.1 seconds
  206. //          TIMER_GETABSOLUTETIME - to get the absolute system time
  207. //          TIMER_GETAPPTIME      - to get the current time
  208. //          TIMER_GETELAPSEDTIME  - to get the time that elapsed between 
  209. //                                  TIMER_GETELAPSEDTIME calls
  210. //-----------------------------------------------------------------------------
  211. FLOAT __stdcall DXUtil_Timer( TIMER_COMMAND command )
  212. {
  213.     static BOOL     m_bTimerInitialized = FALSE;
  214.     static BOOL     m_bUsingQPF         = FALSE;
  215.     static BOOL     m_bTimerStopped     = TRUE;
  216.     static LONGLONG m_llQPFTicksPerSec  = 0;
  217.     // Initialize the timer
  218.     if( FALSE == m_bTimerInitialized )
  219.     {
  220.         m_bTimerInitialized = TRUE;
  221.         // Use QueryPerformanceFrequency() to get frequency of timer.  If QPF is
  222.         // not supported, we will timeGetTime() which returns milliseconds.
  223.         LARGE_INTEGER qwTicksPerSec;
  224.         m_bUsingQPF = QueryPerformanceFrequency( &qwTicksPerSec );
  225.         if( m_bUsingQPF )
  226.             m_llQPFTicksPerSec = qwTicksPerSec.QuadPart;
  227.     }
  228.     if( m_bUsingQPF )
  229.     {
  230.         static LONGLONG m_llStopTime        = 0;
  231.         static LONGLONG m_llLastElapsedTime = 0;
  232.         static LONGLONG m_llBaseTime        = 0;
  233.         double fTime;
  234.         double fElapsedTime;
  235.         LARGE_INTEGER qwTime;
  236.         
  237.         // Get either the current time or the stop time, depending
  238.         // on whether we're stopped and what command was sent
  239.         if( m_llStopTime != 0 && command != TIMER_START && command != TIMER_GETABSOLUTETIME)
  240.             qwTime.QuadPart = m_llStopTime;
  241.         else
  242.             QueryPerformanceCounter( &qwTime );
  243.         // Return the elapsed time
  244.         if( command == TIMER_GETELAPSEDTIME )
  245.         {
  246.             fElapsedTime = (double) ( qwTime.QuadPart - m_llLastElapsedTime ) / (double) m_llQPFTicksPerSec;
  247.             m_llLastElapsedTime = qwTime.QuadPart;
  248.             return (FLOAT) fElapsedTime;
  249.         }
  250.     
  251.         // Return the current time
  252.         if( command == TIMER_GETAPPTIME )
  253.         {
  254.             double fAppTime = (double) ( qwTime.QuadPart - m_llBaseTime ) / (double) m_llQPFTicksPerSec;
  255.             return (FLOAT) fAppTime;
  256.         }
  257.     
  258.         // Reset the timer
  259.         if( command == TIMER_RESET )
  260.         {
  261.             m_llBaseTime        = qwTime.QuadPart;
  262.             m_llLastElapsedTime = qwTime.QuadPart;
  263.             m_llStopTime        = 0;
  264.             m_bTimerStopped     = FALSE;
  265.             return 0.0f;
  266.         }
  267.     
  268.         // Start the timer
  269.         if( command == TIMER_START )
  270.         {
  271.             if( m_bTimerStopped )
  272.                 m_llBaseTime += qwTime.QuadPart - m_llStopTime;
  273.             m_llStopTime = 0;
  274.             m_llLastElapsedTime = qwTime.QuadPart;
  275.             m_bTimerStopped = FALSE;
  276.             return 0.0f;
  277.         }
  278.     
  279.         // Stop the timer
  280.         if( command == TIMER_STOP )
  281.         {
  282.             m_llStopTime = qwTime.QuadPart;
  283.             m_llLastElapsedTime = qwTime.QuadPart;
  284.             m_bTimerStopped = TRUE;
  285.             return 0.0f;
  286.         }
  287.     
  288.         // Advance the timer by 1/10th second
  289.         if( command == TIMER_ADVANCE )
  290.         {
  291.             m_llStopTime += m_llQPFTicksPerSec/10;
  292.             return 0.0f;
  293.         }
  294.         if( command == TIMER_GETABSOLUTETIME )
  295.         {
  296.             fTime = qwTime.QuadPart / (double) m_llQPFTicksPerSec;
  297.             return (FLOAT) fTime;
  298.         }
  299.         return -1.0f; // Invalid command specified
  300.     }
  301.     else
  302.     {
  303.         // Get the time using timeGetTime()
  304.         static double m_fLastElapsedTime  = 0.0;
  305.         static double m_fBaseTime         = 0.0;
  306.         static double m_fStopTime         = 0.0;
  307.         double fTime;
  308.         double fElapsedTime;
  309.         
  310.         // Get either the current time or the stop time, depending
  311.         // on whether we're stopped and what command was sent
  312.         if( m_fStopTime != 0.0 && command != TIMER_START && command != TIMER_GETABSOLUTETIME)
  313.             fTime = m_fStopTime;
  314.         else
  315.             fTime = timeGetTime() * 0.001;
  316.     
  317.         // Return the elapsed time
  318.         if( command == TIMER_GETELAPSEDTIME )
  319.         {   
  320.             fElapsedTime = (double) (fTime - m_fLastElapsedTime);
  321.             m_fLastElapsedTime = fTime;
  322.             return (FLOAT) fElapsedTime;
  323.         }
  324.     
  325.         // Return the current time
  326.         if( command == TIMER_GETAPPTIME )
  327.         {
  328.             return (FLOAT) (fTime - m_fBaseTime);
  329.         }
  330.     
  331.         // Reset the timer
  332.         if( command == TIMER_RESET )
  333.         {
  334.             m_fBaseTime         = fTime;
  335.             m_fLastElapsedTime  = fTime;
  336.             m_fStopTime         = 0;
  337.             m_bTimerStopped     = FALSE;
  338.             return 0.0f;
  339.         }
  340.     
  341.         // Start the timer
  342.         if( command == TIMER_START )
  343.         {
  344.             if( m_bTimerStopped )
  345.                 m_fBaseTime += fTime - m_fStopTime;
  346.             m_fStopTime = 0.0f;
  347.             m_fLastElapsedTime  = fTime;
  348.             m_bTimerStopped = FALSE;
  349.             return 0.0f;
  350.         }
  351.     
  352.         // Stop the timer
  353.         if( command == TIMER_STOP )
  354.         {
  355.             m_fStopTime = fTime;
  356.             m_fLastElapsedTime  = fTime;
  357.             m_bTimerStopped = TRUE;
  358.             return 0.0f;
  359.         }
  360.     
  361.         // Advance the timer by 1/10th second
  362.         if( command == TIMER_ADVANCE )
  363.         {
  364.             m_fStopTime += 0.1f;
  365.             return 0.0f;
  366.         }
  367.         if( command == TIMER_GETABSOLUTETIME )
  368.         {
  369.             return (FLOAT) fTime;
  370.         }
  371.         return -1.0f; // Invalid command specified
  372.     }
  373. }
  374. //-----------------------------------------------------------------------------
  375. // Name: DXUtil_ConvertAnsiStringToWide()
  376. // Desc: This is a UNICODE conversion utility to convert a CHAR string into a
  377. //       WCHAR string. cchDestChar defaults -1 which means it 
  378. //       assumes strDest is large enough to store strSource
  379. //-----------------------------------------------------------------------------
  380. VOID DXUtil_ConvertAnsiStringToWide( WCHAR* wstrDestination, const CHAR* strSource, 
  381.                                      int cchDestChar )
  382. {
  383.     if( wstrDestination==NULL || strSource==NULL )
  384.         return;
  385.     if( cchDestChar == -1 )
  386.         cchDestChar = strlen(strSource)+1;
  387.     MultiByteToWideChar( CP_ACP, 0, strSource, -1, 
  388.                          wstrDestination, cchDestChar-1 );
  389.     wstrDestination[cchDestChar-1] = 0;
  390. }
  391. //-----------------------------------------------------------------------------
  392. // Name: DXUtil_ConvertWideStringToAnsi()
  393. // Desc: This is a UNICODE conversion utility to convert a WCHAR string into a
  394. //       CHAR string. cchDestChar defaults -1 which means it 
  395. //       assumes strDest is large enough to store strSource
  396. //-----------------------------------------------------------------------------
  397. VOID DXUtil_ConvertWideStringToAnsi( CHAR* strDestination, const WCHAR* wstrSource, 
  398.                                      int cchDestChar )
  399. {
  400.     if( strDestination==NULL || wstrSource==NULL )
  401.         return;
  402.     if( cchDestChar == -1 )
  403.         cchDestChar = wcslen(wstrSource)+1;
  404.     WideCharToMultiByte( CP_ACP, 0, wstrSource, -1, strDestination, 
  405.                          cchDestChar-1, NULL, NULL );
  406.     strDestination[cchDestChar-1] = 0;
  407. }
  408. //-----------------------------------------------------------------------------
  409. // Name: DXUtil_ConvertGenericStringToAnsi()
  410. // Desc: This is a UNICODE conversion utility to convert a TCHAR string into a
  411. //       CHAR string. cchDestChar defaults -1 which means it 
  412. //       assumes strDest is large enough to store strSource
  413. //-----------------------------------------------------------------------------
  414. VOID DXUtil_ConvertGenericStringToAnsi( CHAR* strDestination, const TCHAR* tstrSource, 
  415.                                         int cchDestChar )
  416. {
  417.     if( strDestination==NULL || tstrSource==NULL || cchDestChar == 0 )
  418.         return;
  419. #ifdef _UNICODE
  420.     DXUtil_ConvertWideStringToAnsi( strDestination, tstrSource, cchDestChar );
  421. #else
  422.     if( cchDestChar == -1 )
  423.     {
  424.         strcpy( strDestination, tstrSource );
  425.     }
  426.     else
  427.     {
  428.         strncpy( strDestination, tstrSource, cchDestChar );
  429.         strDestination[cchDestChar-1] = '';
  430.     }
  431. #endif
  432. }
  433. //-----------------------------------------------------------------------------
  434. // Name: DXUtil_ConvertGenericStringToWide()
  435. // Desc: This is a UNICODE conversion utility to convert a TCHAR string into a
  436. //       WCHAR string. cchDestChar defaults -1 which means it 
  437. //       assumes strDest is large enough to store strSource
  438. //-----------------------------------------------------------------------------
  439. VOID DXUtil_ConvertGenericStringToWide( WCHAR* wstrDestination, const TCHAR* tstrSource, 
  440.                                         int cchDestChar )
  441. {
  442.     if( wstrDestination==NULL || tstrSource==NULL || cchDestChar == 0 )
  443.         return;
  444. #ifdef _UNICODE
  445.     if( cchDestChar == -1 )
  446.     {
  447.         wcscpy( wstrDestination, tstrSource );
  448.     }
  449.     else
  450.     {
  451.         wcsncpy( wstrDestination, tstrSource, cchDestChar );
  452.         wstrDestination[cchDestChar-1] = L'';
  453.     }
  454. #else
  455.     DXUtil_ConvertAnsiStringToWide( wstrDestination, tstrSource, cchDestChar );
  456. #endif
  457. }
  458. //-----------------------------------------------------------------------------
  459. // Name: DXUtil_ConvertAnsiStringToGeneric()
  460. // Desc: This is a UNICODE conversion utility to convert a CHAR string into a
  461. //       TCHAR string. cchDestChar defaults -1 which means it 
  462. //       assumes strDest is large enough to store strSource
  463. //-----------------------------------------------------------------------------
  464. VOID DXUtil_ConvertAnsiStringToGeneric( TCHAR* tstrDestination, const CHAR* strSource, 
  465.                                         int cchDestChar )
  466. {
  467.     if( tstrDestination==NULL || strSource==NULL || cchDestChar == 0 )
  468.         return;
  469.         
  470. #ifdef _UNICODE
  471.     DXUtil_ConvertAnsiStringToWide( tstrDestination, strSource, cchDestChar );
  472. #else
  473.     if( cchDestChar == -1 )
  474.     {
  475.         strcpy( tstrDestination, strSource );
  476.     }
  477.     else
  478.     {
  479.         strncpy( tstrDestination, strSource, cchDestChar );
  480.         tstrDestination[cchDestChar-1] = '';
  481.     }
  482. #endif
  483. }
  484. //-----------------------------------------------------------------------------
  485. // Name: DXUtil_ConvertAnsiStringToGeneric()
  486. // Desc: This is a UNICODE conversion utility to convert a WCHAR string into a
  487. //       TCHAR string. cchDestChar defaults -1 which means it 
  488. //       assumes strDest is large enough to store strSource
  489. //-----------------------------------------------------------------------------
  490. VOID DXUtil_ConvertWideStringToGeneric( TCHAR* tstrDestination, const WCHAR* wstrSource, 
  491.                                         int cchDestChar )
  492. {
  493.     if( tstrDestination==NULL || wstrSource==NULL || cchDestChar == 0 )
  494.         return;
  495. #ifdef _UNICODE
  496.     if( cchDestChar == -1 )
  497.     {
  498.         wcscpy( tstrDestination, wstrSource );
  499.     }
  500.     else
  501.     {
  502.         wcsncpy( tstrDestination, wstrSource, cchDestChar );
  503.         tstrDestination[cchDestChar-1] = L'';
  504.     }
  505. #else
  506.     DXUtil_ConvertWideStringToAnsi( tstrDestination, wstrSource, cchDestChar );
  507. #endif
  508. }
  509. //-----------------------------------------------------------------------------
  510. // Name: _DbgOut()
  511. // Desc: Outputs a message to the debug stream
  512. //-----------------------------------------------------------------------------
  513. HRESULT _DbgOut( TCHAR* strFile, DWORD dwLine, HRESULT hr, TCHAR* strMsg )
  514. {
  515.     TCHAR buffer[256];
  516.     wsprintf( buffer, _T("%s(%ld): "), strFile, dwLine );
  517.     OutputDebugString( buffer );
  518.     OutputDebugString( strMsg );
  519.     if( hr )
  520.     {
  521.         wsprintf( buffer, _T("(hr=%08lx)n"), hr );
  522.         OutputDebugString( buffer );
  523.     }
  524.     OutputDebugString( _T("n") );
  525.     return hr;
  526. }
  527. //-----------------------------------------------------------------------------
  528. // Name: DXUtil_Trace()
  529. // Desc: Outputs to the debug stream a formatted string with a variable-
  530. //       argument list.
  531. //-----------------------------------------------------------------------------
  532. VOID DXUtil_Trace( TCHAR* strMsg, ... )
  533. {
  534. #if defined(DEBUG) | defined(_DEBUG)
  535.     TCHAR strBuffer[512];
  536.     
  537.     va_list args;
  538.     va_start(args, strMsg);
  539.     _vsntprintf( strBuffer, 512, strMsg, args );
  540.     va_end(args);
  541.     OutputDebugString( strBuffer );
  542. #else
  543.     UNREFERENCED_PARAMETER(strMsg);
  544. #endif
  545. }
  546. //-----------------------------------------------------------------------------
  547. // Name: DXUtil_ConvertStringToGUID()
  548. // Desc: Converts a string to a GUID
  549. //-----------------------------------------------------------------------------
  550. BOOL DXUtil_ConvertStringToGUID( const TCHAR* strIn, GUID* pGuidOut )
  551. {
  552.     UINT aiTmp[10];
  553.     if( _stscanf( strIn, TEXT("{%8X-%4X-%4X-%2X%2X-%2X%2X%2X%2X%2X%2X}"),
  554.                     &pGuidOut->Data1, 
  555.                     &aiTmp[0], &aiTmp[1], 
  556.                     &aiTmp[2], &aiTmp[3],
  557.                     &aiTmp[4], &aiTmp[5],
  558.                     &aiTmp[6], &aiTmp[7],
  559.                     &aiTmp[8], &aiTmp[9] ) != 11 )
  560.     {
  561.         ZeroMemory( pGuidOut, sizeof(GUID) );
  562.         return FALSE;
  563.     }
  564.     else
  565.     {
  566.         pGuidOut->Data2       = (USHORT) aiTmp[0];
  567.         pGuidOut->Data3       = (USHORT) aiTmp[1];
  568.         pGuidOut->Data4[0]    = (BYTE) aiTmp[2];
  569.         pGuidOut->Data4[1]    = (BYTE) aiTmp[3];
  570.         pGuidOut->Data4[2]    = (BYTE) aiTmp[4];
  571.         pGuidOut->Data4[3]    = (BYTE) aiTmp[5];
  572.         pGuidOut->Data4[4]    = (BYTE) aiTmp[6];
  573.         pGuidOut->Data4[5]    = (BYTE) aiTmp[7];
  574.         pGuidOut->Data4[6]    = (BYTE) aiTmp[8];
  575.         pGuidOut->Data4[7]    = (BYTE) aiTmp[9];
  576.         return TRUE;
  577.     }
  578. }
  579. //-----------------------------------------------------------------------------
  580. // Name: DXUtil_ConvertGUIDToString()
  581. // Desc: Converts a GUID to a string 
  582. //-----------------------------------------------------------------------------
  583. VOID DXUtil_ConvertGUIDToString( const GUID* pGuidIn, TCHAR* strOut )
  584. {
  585.     _stprintf( strOut, TEXT("{%0.8X-%0.4X-%0.4X-%0.2X%0.2X-%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X}"),
  586.                pGuidIn->Data1, pGuidIn->Data2, pGuidIn->Data3,
  587.                pGuidIn->Data4[0], pGuidIn->Data4[1],
  588.                pGuidIn->Data4[2], pGuidIn->Data4[3],
  589.                pGuidIn->Data4[4], pGuidIn->Data4[5],
  590.                pGuidIn->Data4[6], pGuidIn->Data4[7] );
  591. }