4

I want to know when the user clicks the menu item he should be able to know the direct X version installed on his machine?

I want to code this in C# in VS2008.

What should i write in the menu item click event? Am a beginner in C#,so dont know where to start from..

can anybody please help? Thanks..

DuckMaestro
  • 15,232
  • 11
  • 67
  • 85
Shweta
  • 45
  • 1
  • 3
  • I've added some code over at http://stackoverflow.com/questions/2673928/net-how-to-detect-if-directx-10-is-supported/28479131#28479131 to check specifically for DX10 via the D3DX10CheckVersion function (Platform Invoke). There may be similar functions which exist for DX9, DX11 – Dr. Andrew Burnett-Thompson Feb 12 '15 at 14:53
  • Also see http://stackoverflow.com/q/17130764/632951 – Pacerier Nov 10 '15 at 15:50

2 Answers2

3

This may help: .NET How to detect if DirectX 10 is supported?.

Edit:

Below is some better code I think. The best I can come up with is a check based on Windows version in the case of DX10 or DX11. This is not 100% accurate (because Vista can be upgraded to DX11 but I do not check for this), but better than nothing.

    private int GetDirectxMajorVersion()
    {
        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;
                        }
                    }
                }
            }
        }

        return directxMajorVersion;
    }
Community
  • 1
  • 1
DuckMaestro
  • 15,232
  • 11
  • 67
  • 85
  • This shows directX 9 installed on my system.But on checking through Dxdiag in run commnad i can see directX 11 installed on my system.Now how to get the right version on my system? – Shweta May 28 '11 at 08:59
  • Strange. Same for me now that I try it out. DirectX 10 and 11 must use a different part of the registry. Since DX10 is closely tied to Vista, and DX11 closely tied to Win7, I suppose you could use a combination of the above check, with an additional check for Vista or Win7. – DuckMaestro May 28 '11 at 19:12
  • i tried the same part of code to check in Vista(on Virtual Machine),thats also showing DirectX 9 .whereas i havent installed direct x on my virtual machine.Dxdiag shows DX 10.Can u please help out where should i proceed and how to write it.Thanks. – Shweta May 30 '11 at 04:15
  • Thanks but i tried some other solution. – Shweta Jun 09 '11 at 10:02
  • What other solution? If it works better than this it'd be great to know. (You can post an answer to your own question on SO) – DuckMaestro Jun 09 '11 at 16:52
0

Found this question linked in another but I see the solution is not peffect so I post my idea of how to solve the problem. But beware: it very, very slow.

EDIT: Removed registry check method because it works only for Dx <=9 (thx @Telanor)

This method is very, very slow, but only one I figured out that is 100% accurate

private static int checkdxversion_dxdiag()
{
    Process.Start("dxdiag", "/x dxv.xml");
    while (!File.Exists("dxv.xml"))
        Thread.Sleep(1000);
    XmlDocument doc = new XmlDocument();
    doc.Load("dxv.xml");
    XmlNode dxd = doc.SelectSingleNode("//DxDiag");
    XmlNode dxv = dxd.SelectSingleNode("//DirectXVersion");

    return Convert.ToInt32(dxv.InnerText.Split(' ')[1]);
}
Peuczynski
  • 4,591
  • 1
  • 19
  • 33