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

No9 2003-08-16 02:49:36
有没有什么正式的API可以检测DirectX的版本号呀?
不需要什么搜索注册表的方法!
...全文
160 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
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的版本的

19,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧