CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2013
    Posts
    17

    Problem with marshaling WebBrowser2 com object

    Hi,
    I have main thread that creates an WebBrowser2 COM object. and i want to invoke JScript functions on it from another thread.
    i try to use GIT but still doesn't work for me..
    there is a problem with marshal WebBrowser2 for JScript?

  2. #2
    Join Date
    Apr 2013
    Posts
    17

    Re: Problem with marshaling WebBrowser2 com object

    CODE:

    MAIN THREAD
    {...
    ATL::CComPtr<IWebBrowser2> m_spWebBrowser;
    m_spWebBrowser.CoCreateInstance(__uuidof(WebBrowser), NULL);
    DispEventAdvise((IUnknown*)m_spWebBrowser)

    ///
    IUnknown* pIUnknown = NULL;
    IGlobalInterfaceTable* pIGlobalInterfaceTable = NULL;


    ::CoCreateInstance
    (
    CLSID_StdGlobalInterfaceTable,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IGlobalInterfaceTable,
    (void **)&pIGlobalInterfaceTable
    );
    if (pIGlobalInterfaceTable)
    {
    /* QI the original interface pointer for its IUnknown interface. */
    m_spWebBrowser -> QueryInterface (IID_IUnknown, (void**)&pIUnknown);
    if (pIUnknown)
    {
    /* Register this interface pointer in GIT. */
    /* A cookie, identifying the interface pointer*/
    /* is returned. */
    /* No need to call pIUnknown -> AddRef(). */
    /* Another thread can retrieve the pIUnknown */
    /* using the cookie. */
    pIGlobalInterfaceTable -> RegisterInterfaceInGlobal
    (
    pIUnknown,
    __uuidof(IWebBrowser2Ptr),
    &m_dwCookie
    );
    pIUnknown -> Release();
    pIUnknown = NULL;
    }

    WORKER THREAD:
    DWORD dwCookie = (DWORD)lpvParameter;
    IWebBrowser2* pISimpleCOMObject2 = NULL;
    IGlobalInterfaceTable* pIGlobalInterfaceTable = NULL;
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if (FAILED(hr)) return; //Needs to add error log here.
    CoCreateInstance
    (
    CLSID_StdGlobalInterfaceTable,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IGlobalInterfaceTable,
    (void **)&pIGlobalInterfaceTable
    );
    if (pIGlobalInterfaceTable)
    {
    pIGlobalInterfaceTable -> GetInterfaceFromGlobal
    (
    dwCookie,
    __uuidof(IWebBrowser2Ptr),
    (void**)&(pThis->m_spWebBrowserCtrl)
    );
    }

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Problem with marshaling WebBrowser2 com object

    What doesn't work?

  4. #4
    Join Date
    Apr 2013
    Posts
    17

    Re: Problem with marshaling WebBrowser2 com object

    WORKER THREAD:
    When i'm tring:
    ATL::CComPtr<IDispatch>& spDisp_;
    IWebBrowser2* m_spWebBrowserCtrl;
    spDisp_ = NULL;

    MSHTML::IHTMLDocument2Ptr spDoc = NULL;
    HRESULT hr = m_spWebBrowserCtrl->get_Document((IDispatch**)&spDoc);

    /////!!!! HERE hr = FAIL!
    if (FAILED(hr) || (NULL == spDoc)) {
    return false;
    }

    hr = spDoc->get_Script(&spDisp_);

    at the main thread it works.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Problem with marshaling WebBrowser2 com object

    Quote Originally Posted by evilGil View Post
    Code:
    ...
      MSHTML::IHTMLDocument2Ptr spDoc = NULL;
      HRESULT hr = m_spWebBrowserCtrl->get_Document((IDispatch**)&spDoc);
    
    /////!!!! HERE hr = FAIL!
      if (FAILED(hr) || (NULL == spDoc)) {
        return false;
      }
    What is the value of hr ?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured