Re: Pass CComPrt to and from function
Hi Igor,
Thanks for your reply. If I add more details of my code as follows,
would it still be ok?
//************ Header file *********
class CLRHost
{
public:
CLRHost();
virtual ~CLRHost();
CComPtr<ICorRuntimeHost> GetCComPtr(void);
SetComPtr(CComPtr<ICorRuntimeHost>);
private:
CComPtr<ICorRuntimeHost> rntHost;
CComPtr<_AppDomain> spDefAppDomain;
CComPtr<_ObjectHandle> spObjectHandle;
CComPtr<IDispatch> pDisp;
};
//************* Class implementation (.Cpp file) ***
CComPtr<ICorRuntimeHost> CLRHost::GetCComPtr(void)
{
return rntHost;
}
void CLRHost::SetCComPtr(CComPtr<ICorRuntimeHost> _rntHost)
{
rntHost = _rntHost;
}
....
....
....
//************** Call to the clrHost object to set/get CComPtr ****
CLRHost* clrHost;
int CreateCLRHost()
{
clrHost = new clrHost();
CComPtr<ICorRuntimeHost> spRuntimeHost;
HRESULT hr = CorBindToRuntimeEx( NULL,
L"wks", TARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN |
STARTUP_CONCURRENT_GC,
CLSID_CorRuntimeHost,
IID_ICorRuntimeHost,
(void**)&spRuntimeHost //pointer to CLR
);
clrHost.SetCComPtr(spRuntimeHost);
}
int StartCLRHost()
{
CComPtr<ICorRuntimeHost> host;
host = clrHost.GetCComPtr();
host.Start;
...
...
}
Here in CreateCLRHost function I create a spRuntimeHost object Then I
pass it to the clrHost class and using = operator make a local copy of
it.
1. Does = operator creates a true copy of the spRuntimeHost object or
adds reference to the same one that I passed in?
2. Is spRuntimeHost object destroyed after I leave the CreateCLRHost
function?
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?
Thanks,
Bob
Igor Tandetnik wrote:
brosembob@yahoo.com wrote:
I'm trying to use CComPtr class. What's the right way to pass to and
return from function CComPrt object? Following is the snippet of code
that I have so far. It compiles and seems to do what I need, but I'm
not sure if it's Ok to pass entire class back and forth.
It's Ok. Your code looks good to me.
--
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