I am using CComPtr to hold a pointer to a com object.
I also wrapped the resource with a class:
class ResourceWrapper {
public:
ResourceWrapper()
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
HRESULT hr = S_OK;
if (FAILED( hr = CoCreateInstance(CLSID_Resource, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&pResource)))||pResource==NULL)
{
throw std::runtime_error("failed to create instance");
}
}
~ResourceWrapper()
{
pResource =NULL;
CoUninitialize();
}
CComPtr<IResource> Get()
{
return pResource;
}
private:
CComPtr<IResource> pResource;
ResourceWrapper(const ResourceWrapper&);
ResourceWrapper operator=(const ResourceWrapper&);
};
but then I thought that maybe CComPtr is implementing RAII and then the Wrapper I created is unnecessary.
I tried to google it, but I didn't understand if I need a wrapper or not.
SO my question is, if I use CComPtr, do I need to also create a wrapper?