简体   繁体   English

如何检查DirectX是否可用?

[英]How to check whether DirectX is available?

Currently I develop a projekt in C#. 目前,我在C#中开发了一个项目。 In this project I use the DirectX API. 在此项目中,我使用DirectX API。 Now I want to implement a function to check whether DirectX is available or not? 现在,我想实现一个功能来检查DirectX是否可用?

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? 您是否需要检测系统中是否存在与DirectX兼容的GPU,以便可以创建Direct3D9设备,而在某些虚拟操作系统等中却不是这种情况? 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. 可以通过查看Windows \\ System32文件夹来检查DirectX安装本身是否存在。 For example, check d3d9d.dll, and D3DX9_43.dll. 例如,检查d3d9d.dll和D3DX9_43.dll。

Another way to get the DirectX - Version: 获得DirectX的另一种方法-版本:

    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();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM