Currently I develop a projekt in C#. In this project I use the DirectX API. Now I want to implement a function to check whether DirectX is available or not?
Do you have an idea how to do this?
Thank you for your help!
Currently I develop a projekt in C#. In this project I use the DirectX API. Now I want to implement a function to check whether DirectX is available or not?
Do you have an idea how to do this?
Thank you for your help!
Do you need to detect if there's DirectX compatible GPU in the system, so that Direct3D9 device can be created, which is not the case with some virtual operating systems etc? That one can be tested simply by creating a device instance and catching the exception it possibly throws.
DirectX install existence itself can be checked by looking into Windows\System32 folder. For example, check d3d9d.dll, and D3DX9_43.dll.
Another way to get the DirectX - Version:
void CheckDirectXMajorVersion()
{
int directxMajorVersion = 0;
var OSVersion = Environment.OSVersion;
// if Windows Vista or later
if (OSVersion.Version.Major >= 6)
{
// if Windows 7 or later
if (OSVersion.Version.Major > 6 || OSVersion.Version.Minor >= 1)
{
directxMajorVersion = 11;
}
// if Windows Vista
else
{
directxMajorVersion = 10;
}
}
// if Windows XP or earlier.
else
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\DirectX"))
{
string versionStr = key.GetValue("Version") as string;
if (!string.IsNullOrEmpty(versionStr))
{
var versionComponents = versionStr.Split('.');
if (versionComponents.Length > 1)
{
int directXLevel;
if (int.TryParse(versionComponents[1], out directXLevel))
{
directxMajorVersion = directXLevel;
}
}
}
}
}
Console.WriteLine("DirectX Version: " + directxMajorVersion.ToString());
Console.ReadKey();
}