Search This Blog

Monday, May 25, 2009

IGlobalInterfaceTable alternate for marshalling in multithreaded enviroment



typedef CComQIPtr<IWebBrowser2,&IID_IWebBrowser2> IWebBrowserQIPtr;
CComPtr<IDispatch> spBrowserPointer ;
IWebBrowserQIPtr pBrowserPtr;
HRESULT hres = S_OK;
DWORD dwCookie = 0;
//Create the GIT
IGlobalInterfaceTable* pGlobalInterfaceTable = NULL;
hres = ::CoCreateInstance(CLSID_StdGlobalInterfaceTable,NULL,CLSCTX_INPROC_SERVER,IID_IGlobalInterfaceTable,(void**)&pGlobalInterfaceTable);
//Register the interface in the GIT
hres = pGlobalInterfaceTable ->RegisterInterfaceInGlobal(pBrowserPtr,IID_IWebBrowser2,&dwCookie);

//this can be used in were ever we unmarshall and use.
//hres =pGlobalInterfaceTable->GetInterfaceFromGlobal(dwCookie,IID_IWebBrowser2,(void**)&pWebBrowserPtr);

//this should be called after using and remove the entry from table
//pGlobalInterfaceTable->RevokeInterfaceFromGlobal(dwCookie);
pGlobalInterfaceTable->Release( );//Don't need the GIT

No comments: