CComPtr Question

  • Thread starter Thread starter Rob Schieber
  • Start date Start date
R

Rob Schieber

Hey guys,

Quick Question. Lets say Im using the XMLHTTPObject to return an
IStream. In General, is it better to return the object as
CComPtr<IStream> spIstream;
QueryInterface.. &spIstream and not worry about Release, or to use
(IStream*)varValue.punkval then use release? I guess the big question
for me is, should I always use smartpointers to deal w/ COM objects? Or
are there situations where manually using addref/release are better?

TIA
 
It is a good idea to release COM objects when you
are finished with them.

Whether you use smart pointers is up to you.

If you are concerned, pay attention to the "Scope"
where your smart pointer is defined.

For example:
.... // other code here
{
CComPtr<IStream> spIstream; // Smart pointer definition
Get the IStream Interface pointer and use it
} // Out of Scope ...You are now certain that the IStream was released
.... other code here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top