Quantcast
Viewing latest article 40
Browse Latest Browse All 45

How do I use _com_ptr_t?

Say I have a class that owns a D3DDevice:

class Thing{public:    Thing()    {        D3D11CreateDevice(..., &device, ...);    }    ~Thing()    {        device->Release();    }private:    ID3D11Device* device;};

From what I understand, I can use _com_ptr_t to ensure that the object gets deleted without my having to explicitly call Release() in the destructor. The problem though is that I can't figure out the correct syntax for the template.

I could find hardly any information on _com_ptr_t, and the closest thing I could find to an answer was this (Japanese) one. Following the syntax there, I get a bunch of compiler errors:

private:    //ID3D11Device* device;    _com_ptr_t <_com_IIID<ID3D11Device, &__uuidof(ID3D11Device)>> device;error C2143: syntax error : missing ';' before '<'error C4430: missing type specifier - int assumed. Note: C++ does not support default-interror C2238: unexpected token(s) preceding ';'error C2065: 'device' : undeclared identifier

By the way, I can use this to return COM pointers from functions and ensure that they get deleted when they leave the caller's scope, right?


Viewing latest article 40
Browse Latest Browse All 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>