N
Nikhil Khedkar
I am working on developing a test application in java. I
use java for UI only. I use JNI to communicate with a VC
MFC DLL. I launch an IE browser instance in one JNI method
(init()), which works fine.
OleInitialize(NULL);
CLSID clsid;
CLSIDFromProgID(OLESTR("InternetExplorer.Application"),
&clsid);
HRESULT hr = CoCreateInstance(clsid, NULL,
CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (void**)
&m_spBrowser);
I store the browser pointer (IWebBrowser2 *) as a C++
class instance variable. BTW, I start a
thread on the native side (_beginthread) which in turn
calls the method that launches the browser.
Previously I was facing the problem of marshalling, the
IWebBrowser2 pointer was getting correupted, when used in
different methods (even the simple properties of
IWebBrowser2 (like IWebBrowser2::fullname) were not
accessible). So now I have added the code of marshalling
after the browser is launched. In almost all the other
methods, I first unmarshall the interface and then
marshall it back at the end of it. This solved my earlier
mentioned problem.
void CIECanvas::MarshallInterface()
{
HRESULT hr;
if(SUCCEEDED(hr = ::CreateStreamOnHGlobal(NULL,
TRUE, &pstm)))
{
LARGE_INTEGER bZero = {0, 0};
pstm->Seek(bZero, STREAM_SEEK_SET, NULL);
if(SUCCEEDED
:CoMarshalInterface(pstm,
IID_IWebBrowser2, m_spBrowser, MSHCTX_INPROC, NULL,
MSHLFLAGS_NORMAL)))
{
pstm->Seek(bZero, STREAM_SEEK_SET,
NULL);
}
}
}
void CIECanvas::UnmarshallInterface()
{
LARGE_INTEGER bZero = {0, 0};
pstm->Seek(bZero, STREAM_SEEK_SET, NULL);
HRESULT hr = ::CoUnmarshalInterface(pstm,
IID_IWebBrowser2, (void**)&m_spBrowser);
if(FAILED(hr))
{
showMessageBox
("CIECanvas::UnmarshallInterface()", "%s %ld", "FAILED.
ERROR CODE = ", GetLastError());
}
}
Then for recording I use AfxConnectionAdvise(), which is
working fine.
The problem I am facing is in Replaying the events.
1)The VM crashes with a hotspot error, when on the first
page some link click event is present, which loads a new
page. One observation here is the VM crashes after
onBeforeNavigate2 or TitleChange events are fired.
2)I also tried Yahoo's registration page (having a lot of
dropdowns and checkboxes), it works fine for the first few
events, but then the VM crashes.
My questions are
1)Does IE handle the events like page loading (tiltle
change etc.) and click on some link in different threads?
How are the events handled (any useful info on this)?
2)How should I fix the problem?
3)Is it related to marshalling of IE COM pointers?
Please replay ASAP,
Nikhil
use java for UI only. I use JNI to communicate with a VC
MFC DLL. I launch an IE browser instance in one JNI method
(init()), which works fine.
OleInitialize(NULL);
CLSID clsid;
CLSIDFromProgID(OLESTR("InternetExplorer.Application"),
&clsid);
HRESULT hr = CoCreateInstance(clsid, NULL,
CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (void**)
&m_spBrowser);
I store the browser pointer (IWebBrowser2 *) as a C++
class instance variable. BTW, I start a
thread on the native side (_beginthread) which in turn
calls the method that launches the browser.
Previously I was facing the problem of marshalling, the
IWebBrowser2 pointer was getting correupted, when used in
different methods (even the simple properties of
IWebBrowser2 (like IWebBrowser2::fullname) were not
accessible). So now I have added the code of marshalling
after the browser is launched. In almost all the other
methods, I first unmarshall the interface and then
marshall it back at the end of it. This solved my earlier
mentioned problem.
void CIECanvas::MarshallInterface()
{
HRESULT hr;
if(SUCCEEDED(hr = ::CreateStreamOnHGlobal(NULL,
TRUE, &pstm)))
{
LARGE_INTEGER bZero = {0, 0};
pstm->Seek(bZero, STREAM_SEEK_SET, NULL);
if(SUCCEEDED
![Smile (: (:](/styles/default/custom/smilies/smile.gif)
IID_IWebBrowser2, m_spBrowser, MSHCTX_INPROC, NULL,
MSHLFLAGS_NORMAL)))
{
pstm->Seek(bZero, STREAM_SEEK_SET,
NULL);
}
}
}
void CIECanvas::UnmarshallInterface()
{
LARGE_INTEGER bZero = {0, 0};
pstm->Seek(bZero, STREAM_SEEK_SET, NULL);
HRESULT hr = ::CoUnmarshalInterface(pstm,
IID_IWebBrowser2, (void**)&m_spBrowser);
if(FAILED(hr))
{
showMessageBox
("CIECanvas::UnmarshallInterface()", "%s %ld", "FAILED.
ERROR CODE = ", GetLastError());
}
}
Then for recording I use AfxConnectionAdvise(), which is
working fine.
The problem I am facing is in Replaying the events.
1)The VM crashes with a hotspot error, when on the first
page some link click event is present, which loads a new
page. One observation here is the VM crashes after
onBeforeNavigate2 or TitleChange events are fired.
2)I also tried Yahoo's registration page (having a lot of
dropdowns and checkboxes), it works fine for the first few
events, but then the VM crashes.
My questions are
1)Does IE handle the events like page loading (tiltle
change etc.) and click on some link in different threads?
How are the events handled (any useful info on this)?
2)How should I fix the problem?
3)Is it related to marshalling of IE COM pointers?
Please replay ASAP,
Nikhil