-
May 6th, 2013, 10:00 AM
#1
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?
-
May 6th, 2013, 10:12 AM
#2
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)
);
}
-
May 6th, 2013, 02:11 PM
#3
Re: Problem with marshaling WebBrowser2 com object
-
May 7th, 2013, 01:37 AM
#4
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.
-
May 7th, 2013, 05:28 AM
#5
Re: Problem with marshaling WebBrowser2 com object
Originally Posted by evilGil
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|