如何使用ComPtr中包含的Direct3D 11指针获取11.1接口?

时间:2014-01-16 20:14:00

标签: c++ windows directx direct3d

我正在关注教程,并且我已经将通常的初始化转换为使用ComPtrs直到这一行:

ID3D11Device*           g_pd3dDevice = nullptr;
ID3D11Device1*          g_pd3dDevice1 = nullptr;
// Obtain the Direct3D 11.1 versions if available
hr = g_pd3dDevice->QueryInterface( __uuidof( ID3D11Device1 ), reinterpret_cast<void**>( &g_pd3dDevice1 ) );

这就是我所期望的直接模拟:

Microsoft::WRL::ComPtr<ID3D11Device>    device = nullptr;
Microsoft::WRL::ComPtr<ID3D11Device1>   device1 = nullptr;
// Obtain the Direct3D 11.1 versions if available
hr = device->QueryInterface(__uuidof(ID3D11Device1), reinterpret_cast<ID3D11Device1**>(&device1));

有很多编译器和智能感知警告(对我来说真的很神秘)。它不喜欢演员表,也不喜欢我使用的是QueryInterface()。

我该怎么办?

错误:

Error   1   error C2440: 'reinterpret_cast' : cannot convert from 'Microsoft::WRL::Details::ComPtrRef<Microsoft::WRL::ComPtr<ID3D11Device1>>' to 'ID3D11Device1 **'
Error   2   error C2660: 'Microsoft::WRL::Details::RemoveIUnknownBase<T>::QueryInterface' : function does not take 1 arguments

智能感知警告(可能有帮助吗?):

18  IntelliSense: function "Microsoft::WRL::Details::RemoveIUnknownBase<T>::QueryInterface [with T=ID3D11Device]" (declared at line 64 of "C:\Program Files (x86)\Windows Kits\8.1\Include\winrt\wrl/client.h") is inaccessible

1 个答案:

答案 0 :(得分:8)

使用ComPtr时,您应该使用::As方法而不是QueryInterface。例如,hr = device.As(&device1);