Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a Direct3D 11 pointer wrapped in ComPtr to get a 11.1 interface?

I'm following tutorials and I've converted the usual initialisation to using ComPtrs up to this line:

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

Here's what I expected to be the straight analog:

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

There's a number of compiler and Intellisense warnings (really cryptic to me). It doesn't like the cast, and it doesn't like how I'm using QueryInterface().

What should I be doing?

Errors:

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 Warnings (could be helpful?):

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
like image 506
chrisp Avatar asked Jan 16 '14 20:01

chrisp


Video Answer


1 Answers

When using ComPtr, you should use the ::As method instead of QueryInterface. For example, hr = device.As(&device1);

like image 85
MooseBoys Avatar answered Nov 14 '22 20:11

MooseBoys