Ref_D_Waldo
Ref_D_Waldo

Reputation: 1

how do I use this Microsoft::WRL::ComPtr<ID3D11Device> as this ID3D11Device* (C++)

The code I am using is C++ for DirectX 11 if this has some relevance.

I am using code that I have been taught to use. The thing is the class that calls my graphics methods has:

Microsoft::WRL::ComPtr<ID3D11Device>

This does not work with some of my methods though. They take:

 ID3D11Device*

Upvotes: 0

Views: 1255

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41127

To convert Microsoft::WRL::ComPtr<T> to a T* pointer, use the Get method.

using Microsoft::WRL::ComPtr;

ComPtr<ID3D11Device> device;

hr = D3D11CreateDevice( ..., device.GetAddressOf(), ... );
if (FAILED(hr))
   // error

...

SomeFunction(device.Get());

See this wiki and Microsoft Docs.

Some older COM smart-pointers automatically converted to T* through an operator, but this is actually a problematic behavior which is why C++ Standard smart-pointers like std::unique_ptr<> use get.() for conversion to a raw pointer. For use of -> or [], the operator overloads take care of it. See this article for more details.

Upvotes: 2

Related Questions