home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / Players / Texture3D / dxutil.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  2.7 KB  |  92 lines

  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.  
  18.  
  19.  
  20. //-----------------------------------------------------------------------------
  21. // Name: DXUtil_GetDXSDKMediaPath()
  22. // Desc: Returns the DirectX SDK media path
  23. //-----------------------------------------------------------------------------
  24. const TCHAR* DXUtil_GetDXSDKMediaPath()
  25. {
  26.     static TCHAR strNull[2] = _T("");
  27.     static TCHAR strPath[MAX_PATH];
  28.     DWORD dwType;
  29.     DWORD dwSize = MAX_PATH;
  30.     HKEY  hKey;
  31.  
  32.     // Open the appropriate registry key
  33.     LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  34.                                 _T("Software\\Microsoft\\DirectX SDK"),
  35.                                 0, KEY_READ, &hKey );
  36.     if( ERROR_SUCCESS != lResult )
  37.         return strNull;
  38.  
  39.     lResult = RegQueryValueEx( hKey, _T("DX81SDK Samples Path"), NULL,
  40.                               &dwType, (BYTE*)strPath, &dwSize );
  41.     RegCloseKey( hKey );
  42.  
  43.     if( ERROR_SUCCESS != lResult )
  44.         return strNull;
  45.  
  46.     _tcscat( strPath, _T("\\Media\\") );
  47.  
  48.     return strPath;
  49. }
  50.  
  51.  
  52.  
  53.  
  54. //-----------------------------------------------------------------------------
  55. // Name: DXUtil_FindMediaFile()
  56. // Desc: Returns a valid path to a DXSDK media file
  57. //-----------------------------------------------------------------------------
  58. HRESULT DXUtil_FindMediaFile( TCHAR* strPath, TCHAR* strFilename )
  59. {
  60.     HANDLE file;
  61.  
  62.     if( NULL==strFilename || NULL==strPath )
  63.         return E_INVALIDARG;
  64.  
  65.     // Check if the file exists in the current directory
  66.     _tcscpy( strPath, strFilename );
  67.  
  68.     file = CreateFile( strPath, GENERIC_READ, FILE_SHARE_READ, NULL, 
  69.                        OPEN_EXISTING, 0, NULL );
  70.     if( INVALID_HANDLE_VALUE != file )
  71.     {
  72.         CloseHandle( file );
  73.         return S_OK;
  74.     }
  75.     
  76.     // Check if the file exists in the current directory
  77.     _stprintf( strPath, _T("%s%s"), DXUtil_GetDXSDKMediaPath(), strFilename );
  78.  
  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.  
  87.     // On failure, just return the file as the path
  88.     _tcscpy( strPath, strFilename );
  89.     return E_FAIL;
  90. }
  91.  
  92.