Re: Pass CComPrt to and from function
brosembob@yahoo.com wrote:
Thanks for your reply. If I add more details of my code as follows,
would it still be ok?
Still looks good.
1. Does = operator creates a true copy of the spRuntimeHost object or
adds reference to the same one that I passed in?
CComPtr's copy constructor and assignment operator simply AddRef the
underlying dumb pointer.
2. Is spRuntimeHost object destroyed after I leave the CreateCLRHost
function?
spRuntimeHost object is indeed destroyed, but the underlying dumb
pointer isn't since clrHost.rntHost now holds a reference to it.
3. If CreateCLRHost function gets called multiple times and many
clrHost objects created, I need each object to have its own
spRuntimeHost instance created. Is it true with this scenario?
I don't quite understand this question. It appears that clrHost is a
global variable. If so, calling CreateCLRHost will result in memory
leak. This is because of "clrHost = new clrHost();" statement and has
nothing to do with your usage of CComPtr. Your program is set up to
handle only one instance of CLRHost class at a time.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925