我希望从.NET代码中找出机器是否支持DirectX 10,最好不使用托管DirectX或XNA程序集。
谢谢您的帮助!
我希望从.NET代码中找出机器是否支持DirectX 10,最好不使用托管DirectX或XNA程序集。
谢谢您的帮助!
// DX10 Supported Function
// See D3DX10CheckVersion http://msdn.microsoft.com/en-us/library/windows/desktop/bb172639(v=vs.85).aspx
[DllImport("d3dx10_43.dll", EntryPoint = "D3DX10CheckVersion", CallingConvention = CallingConvention.StdCall, SetLastError = false)]
private static extern HResult D3DX10CheckVersion(
uint D3DSdkVersion,
uint D3DX10SdkVersion);
public enum HResult : int
{
S_OK = 0x0000,
S_FALSE = 0x0001,
E_NOTIMPL = 0x0002,
E_INVALIDARG = 0x0003,
E_FAIL = 0x0004,
};
bool SupportsDirectX10()
{
// Values taken from d3d10.h to check DirectX version
const uint D3D10_SDK_VERSION = 29;
const uint D3DX10_SDK_VERSION = 43;
// Checks DirectX 10 GPU compatibility with the DirectX10 runtime
// Assumes D3DX10 DLLs present in C:\Windows\System32 or
// C:\Windows\SysWow64 folders (platform dependent)
HResult hResult = D3DX10CheckVersion(D3D10_SDK_VERSION, D3DX10_SDK_VERSION);
return hResult == HResult.S_OK;
}
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX
这里是一个示例
[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;
}
}
}
}
现在,如果你想知道你的显卡是否支持DirectX,这将需要使用XNA或DirectX互操作。
只是一个提示,我现在无法在我的机器上测试那段代码,但那应该可以让你开始 :)