我正在关注教程,并且已经将通常的初始化转换为使用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));

有许多编译器和Intellisense警告(对我来说真的很神秘)。它不喜欢类型转换,也不喜欢我使用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

Intellisense警告(可能有帮助?):
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

最佳答案

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

关于c++ - 如何使用包裹在ComPtr中的Direct3D 11指针来获取11.1接口(interface)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21171916/

10-11 23:23
查看更多