I've recently been going through the process of replacing all my raw pointers with c++11 smart pointers, and now I'm finally done with the exception of my DirectX long pointers.
I'd like to get something along the lines of the below implemented:
std::shared_ptr<IDirect3D9> p_d3d;
p_d3d( Direct3DCreate9(D3D_SDK_VERSION), [](IDirect3D9 *p) {//smart pointer initialization(1)
p->Release();
});
I'm getting the following error from visual studio:
error : call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type
I'd prefer to use std::unique_ptr or std::shared_ptr than CComPtr. Any ideas on why this is happening and possible methods of implementation?
boost::intrusive_ptr
(if I recall its name correctly). unfortunately that building block was not adopted into the C++11 standard. – Cheers and hth. - Alfp->Release()
whenp
is astd::shared_ptr
point to a COM object. Then you still have a pointer but no pointee. As I recall the ATL COM pointers\ fixes this by havingoperator->
returning the pointer downcasted to an interface whereAddRef
andRelease
are private. Anyway that's how I do it. In addition to security, you also want your COM smart pointer to support certain COM things, such as casting to an interface. – Cheers and hth. - Alf