0

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!

Maxim
  • 317
  • 1
  • 5
  • 13
  • Read this: http://stackoverflow.com/questions/3255094/minimum-directx-9-0c-version-and-how-to-check-for-it – Andy Apr 11 '13 at 12:37
  • Which version of DirectX and which OS do you need? Bear in mind that DX10 and DX11 are part of Windows 7 and Windows 8 anyway. – Roger Rowland Apr 11 '13 at 12:48
  • I need the Version 9.0c in Windows XPfessional SP 3. But the software can be installed on win xp, win vista and win 7. Therefor I think I have to check of more then one DX Version.. Is it right? – Maxim Apr 11 '13 at 12:58

2 Answers2

0

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.

Pasi Tuomainen
  • 496
  • 3
  • 10
  • Thank you for your answere. The test to create a device instance is a good idea. You also can check the DirectX Version by execute "dxdiag". – Maxim Apr 12 '13 at 06:59
0

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();
    }
Maxim
  • 317
  • 1
  • 5
  • 13