Getdxver.cpp
上传用户:garry_shen
上传日期:2015-04-15
资源大小:45647k
文件大小:6k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // Getdxver.cpp: implementation of the CGetdxver class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include <dmusici.h>
  6. #include "XMudClient.h"
  7. #include "Getdxver.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. typedef HRESULT(WINAPI * DIRECTDRAWCREATE)( GUID*, LPDIRECTDRAW*, IUnknown* );
  14. typedef HRESULT(WINAPI * DIRECTDRAWCREATEEX)( GUID*, VOID**, REFIID, IUnknown* );
  15. typedef HRESULT(WINAPI * DIRECTINPUTCREATE)( HINSTANCE, DWORD, LPDIRECTINPUT*,
  16.                                              IUnknown* );
  17. CGetdxver::CGetdxver()
  18. {
  19. }
  20. CGetdxver::~CGetdxver()
  21. {
  22. }
  23. void CGetdxver::GetDXVersion( DWORD* pdwDXVersion, DWORD* pdwDXPlatform )
  24. {
  25.     HRESULT              hr;
  26.     HINSTANCE            DDHinst = 0;
  27.     HINSTANCE            DIHinst = 0;
  28.     LPDIRECTDRAW         pDDraw  = 0;
  29.     LPDIRECTDRAW2        pDDraw2 = 0;
  30.     DIRECTDRAWCREATE     DirectDrawCreate   = 0;
  31.     DIRECTDRAWCREATEEX   DirectDrawCreateEx = 0;
  32.     DIRECTINPUTCREATE    DirectInputCreate  = 0;
  33.     OSVERSIONINFO        osVer;
  34.     LPDIRECTDRAWSURFACE  pSurf  = 0;
  35.     LPDIRECTDRAWSURFACE3 pSurf3 = 0;
  36.     LPDIRECTDRAWSURFACE4 pSurf4 = 0;
  37.     osVer.dwOSVersionInfoSize = sizeof(osVer);
  38.     if( !GetVersionEx( &osVer ) ) {
  39.         (*pdwDXPlatform) = 0;
  40.         (*pdwDXVersion)  = 0;
  41.         return;
  42.     }
  43.     if( osVer.dwPlatformId == VER_PLATFORM_WIN32_NT ){
  44.         (*pdwDXPlatform) = VER_PLATFORM_WIN32_NT;
  45.         if( osVer.dwMajorVersion < 4 ){
  46.             (*pdwDXVersion) = 0;
  47.             return;
  48.         }
  49.         if( osVer.dwMajorVersion == 4 ){
  50.             (*pdwDXVersion) = 0x200;
  51.             DIHinst = LoadLibrary( "DINPUT.DLL" );
  52.             if( DIHinst == 0 ){
  53.                 OutputDebugString( "Couldn't LoadLibrary DInputrn" );
  54.                 return;
  55.             }
  56.             DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
  57.                                                                  "DirectInputCreateA" );
  58.             FreeLibrary( DIHinst );
  59.             if( DirectInputCreate == 0 ){
  60.                 OutputDebugString( "Couldn't GetProcAddress DInputCreatern" );
  61.                 return;
  62.             }
  63.             (*pdwDXVersion) = 0x300;
  64.             return;
  65.         }
  66.     }else {
  67.         (*pdwDXPlatform) = VER_PLATFORM_WIN32_WINDOWS;
  68.     }
  69.     DDHinst = LoadLibrary( "DDRAW.DLL" );
  70.     if( DDHinst == 0 ){
  71.         (*pdwDXVersion)  = 0;
  72.         (*pdwDXPlatform) = 0;
  73.         FreeLibrary( DDHinst );
  74.         return;
  75.     }
  76.     DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( DDHinst, "DirectDrawCreate" );
  77.     if( DirectDrawCreate == 0 ){
  78.         (*pdwDXVersion)  = 0;
  79.         (*pdwDXPlatform) = 0;
  80.         FreeLibrary( DDHinst );
  81.         OutputDebugString( "Couldn't LoadLibrary DDrawrn" );
  82.         return;
  83.     }
  84.     hr = DirectDrawCreate( NULL, &pDDraw, NULL );
  85.     if( FAILED(hr) )
  86.     {
  87.         (*pdwDXVersion)  = 0;
  88.         (*pdwDXPlatform) = 0;
  89.         FreeLibrary( DDHinst );
  90.         OutputDebugString( "Couldn't create DDrawrn" );
  91.         return;
  92.     }
  93.     (*pdwDXVersion) = 0x100;
  94.     hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&pDDraw2 );
  95.     if( FAILED(hr) ){
  96.         pDDraw->Release();
  97.         FreeLibrary( DDHinst );
  98.         OutputDebugString( "Couldn't QI DDraw2rn" );
  99.         return;
  100.     }
  101.     pDDraw2->Release();
  102.     (*pdwDXVersion) = 0x200;
  103.     DIHinst = LoadLibrary( "DINPUT.DLL" );
  104.     if( DIHinst == 0 ){
  105.         OutputDebugString( "Couldn't LoadLibrary DInputrn" );
  106.         pDDraw->Release();
  107.         FreeLibrary( DDHinst );
  108.         return;
  109.     }
  110.     DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
  111.                                                        "DirectInputCreateA" );
  112.     if( DirectInputCreate == 0 )
  113.     {
  114.         FreeLibrary( DIHinst );
  115.         FreeLibrary( DDHinst );
  116.         pDDraw->Release();
  117.         OutputDebugString( "Couldn't GetProcAddress DInputCreatern" );
  118.         return;
  119.     }
  120.     (*pdwDXVersion) = 0x300;
  121.     FreeLibrary( DIHinst );
  122.     DDSURFACEDESC ddsd;
  123.     ZeroMemory( &ddsd, sizeof(ddsd) );
  124.     ddsd.dwSize         = sizeof(ddsd);
  125.     ddsd.dwFlags        = DDSD_CAPS;
  126.     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  127.     hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
  128.     if( FAILED(hr) ){
  129.         pDDraw->Release();
  130.         FreeLibrary( DDHinst );
  131.         (*pdwDXVersion) = 0;
  132.         OutputDebugString( "Couldn't Set coop levelrn" );
  133.         return;
  134.     }
  135.     hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
  136.     if( FAILED(hr) ){
  137.         pDDraw->Release();
  138.         FreeLibrary( DDHinst );
  139.         *pdwDXVersion = 0;
  140.         OutputDebugString( "Couldn't CreateSurfacern" );
  141.         return;
  142.     }
  143.     if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
  144.                                        (VOID**)&pSurf3 ) ) )
  145.     {
  146.         pDDraw->Release();
  147.         FreeLibrary( DDHinst );
  148.         return;
  149.     }
  150.     (*pdwDXVersion) = 0x500;
  151.     if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface4,
  152.                                        (VOID**)&pSurf4 ) ) ){
  153.         pDDraw->Release();
  154.         FreeLibrary( DDHinst );
  155.         return;
  156.     }
  157.     (*pdwDXVersion) = 0x600;
  158.     pSurf->Release();
  159.     pDDraw->Release();
  160.     LPDIRECTMUSIC pDMusic = NULL;
  161.     CoInitialize( NULL );
  162.     hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
  163.                            IID_IDirectMusic, (VOID**)&pDMusic );
  164.     if( FAILED(hr) )
  165.     {
  166.         OutputDebugString( "Couldn't create CLSID_DirectMusicrn" );
  167.         FreeLibrary( DDHinst );
  168.         return;
  169.     }
  170.     (*pdwDXVersion) = 0x601;
  171.     pDMusic->Release();
  172.     CoUninitialize();
  173.     LPDIRECTDRAW7 pDD7;
  174.     DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( DDHinst,
  175.                                                        "DirectDrawCreateEx" );
  176.     if( NULL == DirectDrawCreateEx )
  177.     {
  178.         FreeLibrary( DDHinst );
  179.         return;
  180.     }
  181.     if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&pDD7, IID_IDirectDraw7,
  182.                                     NULL ) ) ){
  183.         FreeLibrary( DDHinst );
  184.         return;
  185.     }
  186.     (*pdwDXVersion) = 0x700;
  187.     pDD7->Release();
  188.     FreeLibrary( DDHinst );
  189.     return;
  190. }