I am using a 开发者_JAVA百科worker thread inside a CDialog class.
theApp.m_pWorkerThread = AfxBeginThread(Threadproc,this);
Now I need to pass a global Inerface poiner to the worker thread so as to access a COM object from outside
Can someone tell me the syntax to pass the GIT cookie and access it inside the thread.
Thanks
Well, I will answer this myself
This can be done in 3 ways actually. one way I will brief.
using the CComGitPtr from atlbase.h
Do like this :
CComGitPtr GitPtrName (pointer to the initialized interface)
Now extract the cookie from the DWORD dwCokie = GitPtrName->Detach();
Now pass the cookie as a content of struct(optional) inside the worker thread.
Once you are inside the worker thread, extract the cookie, call CoInitilize, and instantiate the reqiuired interface pointer.
as COMInterfacethatneedMarshalling pReqd.
Now pass the git cookie to the GI table and retrieve the marshalled COM object.
like:
// This is done inide the thread // retrieve the passed cookie as dwCookie CComGITPtr<COMInterfacethatneedMarshalling
pToGITTest(dwCookie); COMInterfacethatneedMarshalling pReqd; pToGITTest.CopyTo(&pReqd);
Now we have pToGITTest inside the thread, fully marshalled, go ahead and enjoy!
Thanks.
精彩评论