.NET How to detect if DirectX 10 is supported?

前端 未结 3 1875
情书的邮戳
情书的邮戳 2021-01-13 13:35

I would like to find out from .NET code whether DirectX 10 is supported on the machine, preferably without using managed DirectX or XNA assemblies.

Thank you in adva

3条回答
  •  执念已碎
    2021-01-13 14:24

    You can have a look at the DirectX version installed on your machine using this key hive

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX
    

    Here's a sample

    [assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,All = "HKEY_LOCAL_MACHINE")]
    class Test
    {
        public int DxLevel
        {
            get
            {
                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))
                                return directXLevel;
                        }
                    }
                    return -1;
                } 
                         }
        }
    }
    

    Now if you want to know whether your video card supports DirectX, this is going to require XNA or DirectX interop.

    Just a note, I couldn't test that code on my machine right now but that should get you started :)

提交回复
热议问题