Search code examples
smart-pointersdirectx-11c++builder-11-alexandria

How to use ComPtr in C++Builder?


I'm trying to implement DX11 in my C++Builder project. All SDK references use the ComPtr<> template, eg:

// Create the DX11 API device object, and get a corresponding context.
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context;

Of course, C++Builder doesn't know ComPtr, so how can I include it, or port over the ComPtr template? Basically, get it to work in C++Builder.

UPDATE

So, someone asked me about the headers. Obviously, I don't have the needed header, hence I'm asking here for a solution.

#include <vcl.h>
#include <winuser.h>
#include <d2d1.h>
#include <d3d11.h>

According to Microsoft, I should include <client.h>, but that one can't be found by C++Builder.


Solution

  • C++Builder has its own smart-interface-pointer classes, such as TComInterface in <utilcls.h>:

    #include <utilcls.h>
    
    TComInterface<ID3D11Device> device;
    TComInterface<ID3D11DeviceContext> context;