有没有什么正式的API可以检测DirectX的版本号呀?

No9 2003-08-16 02:49:36
有没有什么正式的API可以检测DirectX的版本号呀?
不需要什么搜索注册表的方法!
...全文
85 13 打赏 收藏 举报
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
No9 2003-08-26
不好意思,前几天加分总是失败,不知道为什么,拖到今天!
  • 打赏
  • 举报
回复
No9 2003-08-21
谢谢各位,我在微软网站上下载了最新的SDK,找到了该例子,上面的方法好像就是判断核心文件的版本号,得到对应的DirectX的版本号!

加分!
  • 打赏
  • 举报
回复
wqs6 2003-08-19
厉害!
studying
  • 打赏
  • 举报
回复
wpingxia 2003-08-19
DWORD GetDXVersion()
{
DIRECTDRAWCREATE DirectDrawCreate = NULL;
DIRECTDRAWCREATEEX DirectDrawCreateEx = NULL;
DIRECTINPUTCREATE DirectInputCreate = NULL;
HINSTANCE hDDrawDLL = NULL;
HINSTANCE hDInputDLL = NULL;
HINSTANCE hD3D8DLL = NULL;
HINSTANCE hDPNHPASTDLL = NULL;
LPDIRECTDRAW pDDraw = NULL;
LPDIRECTDRAW2 pDDraw2 = NULL;
LPDIRECTDRAWSURFACE pSurf = NULL;
LPDIRECTDRAWSURFACE3 pSurf3 = NULL;
LPDIRECTDRAWSURFACE4 pSurf4 = NULL;
DWORD dwDXVersion = 0;
HRESULT hr;

// First see if DDRAW.DLL even exists.
hDDrawDLL = LoadLibrary( "DDRAW.DLL" );
if( hDDrawDLL == NULL )
{
dwDXVersion = 0;
OutputDebugString( "Couldn't LoadLibrary DDraw\r\n" );
return dwDXVersion;
}

// See if we can create the DirectDraw object.
DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( hDDrawDLL, "DirectDrawCreate" );
if( DirectDrawCreate == NULL )
{
dwDXVersion = 0;
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't GetProcAddress DirectDrawCreate\r\n" );
return dwDXVersion;
}

hr = DirectDrawCreate( NULL, &pDDraw, NULL );
if( FAILED(hr) )
{
dwDXVersion = 0;
FreeLibrary( hDDrawDLL );
OutputDebugString( "Couldn't create DDraw\r\n" );
return dwDXVersion;
}

  • 打赏
  • 举报
回复
wpingxia 2003-08-19
//-----------------------------------------------------------------------------
// Name: GetDXVersion()
// Desc: This function returns the DirectX version number as follows:
// 0x0000 = No DirectX installed
// 0x0100 = DirectX version 1 installed
// 0x0200 = DirectX 2 installed
// 0x0300 = DirectX 3 installed
// 0x0500 = At least DirectX 5 installed.
// 0x0600 = At least DirectX 6 installed.
// 0x0601 = At least DirectX 6.1 installed.
// 0x0700 = At least DirectX 7 installed.
// 0x0800 = At least DirectX 8 installed.
//
// Please note that this code is intended as a general guideline. Your
// app will probably be able to simply query for functionality (via
// QueryInterface) for one or two components.
//
// Please also note:
// "if( dwDXVersion != 0x500 ) return FALSE;" is VERY BAD.
// "if( dwDXVersion < 0x500 ) return FALSE;" is MUCH BETTER.
// to ensure your app will run on future releases of DirectX.
//-----------------------------------------------------------------------------
  • 打赏
  • 举报
回复
wpingxia 2003-08-19
给我信箱,我给你发过去,是个project
  • 打赏
  • 举报
回复
taianmonkey 2003-08-19
补充:
lib 加入 dsetup.lib
#include <Dsetup.h>
DWORD dwVersion;
DWORD dwRevision;
if (DirectXSetupGetVersion(&dwVersion, &dwRevision))
{
// str.Format("DirectX version is %d.%d.%d.%d\n",
// HIWORD(dwVersion), LOWORD(dwVersion),
// HIWORD(dwRevision), LOWORD(dwRevision));

switch(dwVersion)
{
case 0x00000000:
case 0x00040005:
case 0x00040006:
case 0x00040007:
{
CString strTitle,strInfo;
strTitle = GetMultiString(L"DirectDlgTitle");
strInfo = GetMultiString(L"DirectDlgInfo");
::MessageBox(NULL,strInfo,strTitle,MB_OK);
exit(-1);
}
break;
case 0x00040008:
break;
}
}
  • 打赏
  • 举报
回复
duwenyong 2003-08-19
自己写一个如下:
BOOL GetDirectXVersion(DWORD *lpdwVersion, DWORD *lpdwMinorVersion)
{
HKEY hOpen;
DWORD cbData=256;
DWORD dwType;
BYTE Ver[256]="";
DWORD rc;
BOOL bSuccess = TRUE;

if ( (rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\DirectX", 0,
KEY_READ, &hOpen)) == ERROR_SUCCESS)
{
if ((rc = RegQueryValueEx(hOpen,"Version",NULL,&dwType,
Ver, &cbData )) == ERROR_SUCCESS )
{
int v1,v2;
sscanf((LPCSTR)Ver,"%d.%d.%d.%d",&v1,lpdwVersion,lpdwMinorVersion,&v2);
}
else
{
bSuccess = FALSE;
}
RegCloseKey(hOpen);
}
else
bSuccess = FALSE;

return bSuccess;
}

void CDialogDlg::OnButton3()
{
// TODO: Add your control notification handler code here
char ver[256];
DWORD dwVersion;
DWORD dwRevision;
if (GetDirectXVersion(&dwVersion, &dwRevision))
{
sprintf(ver,"DirectX version is %d.%d\n",dwVersion,dwRevision);
MessageBox(ver,"DVR2000",MB_OK);
}
/*
else
MessageBox("errror");
*/

}
  • 打赏
  • 举报
回复
duwenyong 2003-08-19
INT DirectXSetupGetVersion( DWORD *pdwVersion,
DWORD *pdwRevision
);

DWORD dwVersion;
DWORD dwRevision;
if (DirectXSetupGetVersion(&dwVersion, &dwRevision))
{
printf("DirectX version is %d.%d.%d.%d\n",
HIWORD(dwVersion), LOWORD(dwVersion),
HIWORD(dwRevision), LOWORD(dwRevision));
}

Header :dsetup.h
Import library :dsetup.lib
Minimum operating systems :Windows 98
  • 打赏
  • 举报
回复
wpingxia 2003-08-17
There is no direct way to obtain the DirectX version number. However, each version has a characteristic set of objects and interfaces. Because any version of DirectX supports all previous versions, this set of interfaces and objects will be supported by the version in which they are introduced and all subsequent versions. Thus, the preferred way to determine whether your desired version is available is to test for its characteristic objects or interfaces. As long as those are present, your application will work normally even though you might be using a more recent version of DirectX.

For example, suppose you need DirectX 6.1 support. The Microsoft DirectMusic® object (CLSID_DirectMusic) was introduced in DirectX 6.1. You can test for the presence of the DirectMusic object by attempting to create it with CoCreateInstance. If you are successful, you have version 6.1 or later, and you will be able to use all the DirectX 6.1 capabilities.

Rather than provide a detailed list here of each version's characteristic interfaces and objects, you should refer to the DirectX software development kits (SDKs) sample section. One of the samples is a function, GetDXVersion, that includes tests for all DirectX versions. GetDXVersion returns an integer that corresponds to the DirectX version that is present on the system. As long as this integer is greater than or equal to your desired version number, your application will run normally. You can find the sample code under your SDK root folder at \Samples\Multimedia\DXMisc\GetDXVer.

仔细看看,看不明白的话,我翻译给你:)
  • 打赏
  • 举报
回复
No9 2003-08-17
谢谢,上面的老兄!
我大致明白了,上面说没有非常正确的得到版本的方法,应该使用创建对象是否成功来判断!
可以参考GetDXVersion()函数,能否将这个函数贴出来呢?
我还没有找到呢?
  • 打赏
  • 举报
回复
No9 2003-08-16
DirectX SDK到哪里找到?
有看过朋友,能否简单说一下方法?
  • 打赏
  • 举报
回复
gzshd 2003-08-16
DirectX SDK里有一个例子就是检测dx的版本的
  • 打赏
  • 举报
回复
发帖
图形处理/算法

1.9w+

社区成员

VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
帖子事件
创建了帖子
2003-08-16 02:49
社区公告
暂无公告