Search This Blog

Friday, May 15, 2009

Marshalling WebBrowser Pointer

     /* ============================================================================
     #include <mshtml.h> */


     typedef CComQIPtr<IWebBrowser2,&IID_IWebBrowser2>                              IWebBrowserQIPtr;

     IStream** pStream = NULL ;
     pStream = new IStream* ; // free this memory only at the end of parsing.If you are freeing before that parse will fail

     CComPtr<IDispatch> spBrowserPointer ;         
     spBrowserPointer = APPPTR->m_pdlg->m_webBwsrCntrl.get_Application();

     IWebBrowserQIPtr pBrowserPtr;
     pBrowserPtr = spBrowserPointer;

     HRESULT hr = ::CoMarshalInterThreadInterfaceInStream(IID_IWebBrowser2,pBrowserPtr,pStream);    

     DWORD dwStream = 0;

     if( hr == S_OK )
     {
          dwStream = reinterpret_cast<DWORD>( pStream );
     }
     else
     {
          return -1;
     }

     //(*pStream)->Release(); // Do not release this.While calling CoGetInterfaceAndReleaseStream it will be automaticaly released.

     //=============================================================================

No comments: