Getdxver.cpp
上传用户:garry_shen
上传日期:2015-04-15
资源大小:45647k
文件大小:6k
- // Getdxver.cpp: implementation of the CGetdxver class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include <dmusici.h>
- #include "XMudClient.h"
- #include "Getdxver.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- typedef HRESULT(WINAPI * DIRECTDRAWCREATE)( GUID*, LPDIRECTDRAW*, IUnknown* );
- typedef HRESULT(WINAPI * DIRECTDRAWCREATEEX)( GUID*, VOID**, REFIID, IUnknown* );
- typedef HRESULT(WINAPI * DIRECTINPUTCREATE)( HINSTANCE, DWORD, LPDIRECTINPUT*,
- IUnknown* );
- CGetdxver::CGetdxver()
- {
- }
- CGetdxver::~CGetdxver()
- {
- }
- void CGetdxver::GetDXVersion( DWORD* pdwDXVersion, DWORD* pdwDXPlatform )
- {
- HRESULT hr;
- HINSTANCE DDHinst = 0;
- HINSTANCE DIHinst = 0;
- LPDIRECTDRAW pDDraw = 0;
- LPDIRECTDRAW2 pDDraw2 = 0;
- DIRECTDRAWCREATE DirectDrawCreate = 0;
- DIRECTDRAWCREATEEX DirectDrawCreateEx = 0;
- DIRECTINPUTCREATE DirectInputCreate = 0;
- OSVERSIONINFO osVer;
- LPDIRECTDRAWSURFACE pSurf = 0;
- LPDIRECTDRAWSURFACE3 pSurf3 = 0;
- LPDIRECTDRAWSURFACE4 pSurf4 = 0;
- osVer.dwOSVersionInfoSize = sizeof(osVer);
- if( !GetVersionEx( &osVer ) ) {
- (*pdwDXPlatform) = 0;
- (*pdwDXVersion) = 0;
- return;
- }
- if( osVer.dwPlatformId == VER_PLATFORM_WIN32_NT ){
- (*pdwDXPlatform) = VER_PLATFORM_WIN32_NT;
- if( osVer.dwMajorVersion < 4 ){
- (*pdwDXVersion) = 0;
- return;
- }
- if( osVer.dwMajorVersion == 4 ){
- (*pdwDXVersion) = 0x200;
- DIHinst = LoadLibrary( "DINPUT.DLL" );
- if( DIHinst == 0 ){
- OutputDebugString( "Couldn't LoadLibrary DInputrn" );
- return;
- }
- DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
- "DirectInputCreateA" );
- FreeLibrary( DIHinst );
- if( DirectInputCreate == 0 ){
- OutputDebugString( "Couldn't GetProcAddress DInputCreatern" );
- return;
- }
- (*pdwDXVersion) = 0x300;
- return;
- }
- }else {
- (*pdwDXPlatform) = VER_PLATFORM_WIN32_WINDOWS;
- }
- DDHinst = LoadLibrary( "DDRAW.DLL" );
- if( DDHinst == 0 ){
- (*pdwDXVersion) = 0;
- (*pdwDXPlatform) = 0;
- FreeLibrary( DDHinst );
- return;
- }
- DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( DDHinst, "DirectDrawCreate" );
- if( DirectDrawCreate == 0 ){
- (*pdwDXVersion) = 0;
- (*pdwDXPlatform) = 0;
- FreeLibrary( DDHinst );
- OutputDebugString( "Couldn't LoadLibrary DDrawrn" );
- return;
- }
- hr = DirectDrawCreate( NULL, &pDDraw, NULL );
- if( FAILED(hr) )
- {
- (*pdwDXVersion) = 0;
- (*pdwDXPlatform) = 0;
- FreeLibrary( DDHinst );
- OutputDebugString( "Couldn't create DDrawrn" );
- return;
- }
- (*pdwDXVersion) = 0x100;
- hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&pDDraw2 );
- if( FAILED(hr) ){
- pDDraw->Release();
- FreeLibrary( DDHinst );
- OutputDebugString( "Couldn't QI DDraw2rn" );
- return;
- }
- pDDraw2->Release();
- (*pdwDXVersion) = 0x200;
- DIHinst = LoadLibrary( "DINPUT.DLL" );
- if( DIHinst == 0 ){
- OutputDebugString( "Couldn't LoadLibrary DInputrn" );
- pDDraw->Release();
- FreeLibrary( DDHinst );
- return;
- }
- DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
- "DirectInputCreateA" );
- if( DirectInputCreate == 0 )
- {
- FreeLibrary( DIHinst );
- FreeLibrary( DDHinst );
- pDDraw->Release();
- OutputDebugString( "Couldn't GetProcAddress DInputCreatern" );
- return;
- }
- (*pdwDXVersion) = 0x300;
- FreeLibrary( DIHinst );
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(ddsd) );
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
- if( FAILED(hr) ){
- pDDraw->Release();
- FreeLibrary( DDHinst );
- (*pdwDXVersion) = 0;
- OutputDebugString( "Couldn't Set coop levelrn" );
- return;
- }
- hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
- if( FAILED(hr) ){
- pDDraw->Release();
- FreeLibrary( DDHinst );
- *pdwDXVersion = 0;
- OutputDebugString( "Couldn't CreateSurfacern" );
- return;
- }
- if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
- (VOID**)&pSurf3 ) ) )
- {
- pDDraw->Release();
- FreeLibrary( DDHinst );
- return;
- }
- (*pdwDXVersion) = 0x500;
- if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface4,
- (VOID**)&pSurf4 ) ) ){
- pDDraw->Release();
- FreeLibrary( DDHinst );
- return;
- }
- (*pdwDXVersion) = 0x600;
- pSurf->Release();
- pDDraw->Release();
- LPDIRECTMUSIC pDMusic = NULL;
- CoInitialize( NULL );
- hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
- IID_IDirectMusic, (VOID**)&pDMusic );
- if( FAILED(hr) )
- {
- OutputDebugString( "Couldn't create CLSID_DirectMusicrn" );
- FreeLibrary( DDHinst );
- return;
- }
- (*pdwDXVersion) = 0x601;
- pDMusic->Release();
- CoUninitialize();
- LPDIRECTDRAW7 pDD7;
- DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( DDHinst,
- "DirectDrawCreateEx" );
- if( NULL == DirectDrawCreateEx )
- {
- FreeLibrary( DDHinst );
- return;
- }
- if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&pDD7, IID_IDirectDraw7,
- NULL ) ) ){
- FreeLibrary( DDHinst );
- return;
- }
- (*pdwDXVersion) = 0x700;
- pDD7->Release();
- FreeLibrary( DDHinst );
- return;
- }