How do I work with CComPtr
-
Can somebody show me how should I work with an CComPtr pointer. Are there any web links wich I can follow.
CComPtr is a SmartPointer wrapper class specifically designed for COM objects. So when your smart pointer goes out of scope, it will automatically call Release on your object. It is very simple to use. First declare a CComPtr to wrap one of your objects:
CComPtr spDataObj;
Now you can use spDataObj anywhere that you would normally use a pointer to the interface. You do not need to worry about casting or dereferencing or anything like that it is completely transparent.IUnknown *pUnk; ... pUnk->QueryInterface(IID_IDataObject, &spDataObject); //QueryInterface to assign spDataObj->GetData(...); // call member function of the IDataObject interface.
Some other cool things to know are the Attach and Detach members. This will allow you to attach an existing interface pointer to the CComPtr without addrefing it internally, and the Detach method will allow you to remove the internal interface pointer without releasing it. Other than that it should be pretty straight forward, and you may also want to checkout CComQIPtr. That smart pointer object will allow you to query for the interface on assignment, so it will save you one step when you are setting up your pointers. Good Luck
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life! -
Can somebody show me how should I work with an CComPtr pointer. Are there any web links wich I can follow.
Also, check out CComPtr::CoCreateInstance (or was it CreateInstance only?) -- Please state the nature of your medical emergency.
-
Also, check out CComPtr::CoCreateInstance (or was it CreateInstance only?) -- Please state the nature of your medical emergency.
it is
CoCreateInstance
.CreateInstance
is with_com_ptr_t
. Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard