//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
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.