1

Topic: IWebBrowser2 DISPID_QUIT

I cling to launched IE and through Invoke I try to catch events. In particular it is necessary to catch DISPID_DOCUMENTCOMPLETE and  html the loaded page. And it comes, and html from IWebBrowser2 correct, but not always. Through time instead of it comes DISPID_QUIT that generally speaking means closing IE though no closing is present. And after that the delirium begins. DISPID_DOCUMENTCOMPLETE does not come any more. But if to walk around links in IE that it comes, but at attempt to take html pages from IWebBrowser2 there or absolutely other page, or generally nonsense of type "<html> <head> </head> <body> </body> </html>". That is it is clear, what somewhere something falls off, but how it to prevent, or at least to restart process of normal interception? class XWebBrowser2EventsBase {protected: static _ATL_FUNC_INFO BeforeNavigate2Struct; static _ATL_FUNC_INFO DocumentComplete2Struct; static _ATL_FUNC_INFO NavigateErrorStruct; static _ATL_FUNC_INFO OnQuitStruct; static _ATL_FUNC_INFO OnVisibleStruct; static _ATL_FUNC_INFO QuitStruct;} ; class XEventSink: public XWebBrowser2EventsBase, public IDispEventSimpleImpl <1, XEventSink, &DIID_DWebBrowserEvents2> {public: XEventSink (class XBrowser* a_pBrowser); ~XEventSink (); BEGIN_SINK_MAP (XEventSink) SINK_ENTRY_INFO (1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, OnBeforeNavigate2, &BeforeNavigate2Struct) SINK_ENTRY_INFO (1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete, &DocumentComplete2Struct) SINK_ENTRY_INFO (1, DIID_DWebBrowserEvents2, DISPID_NAVIGATEERROR, OnNavigateError, &NavigateErrorStruct) SINK_ENTRY_INFO (1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, OnQuit, &OnQuitStruct) SINK_ENTRY_INFO (1, DIID_DWebBrowserEvents2, DISPID_ONVISIBLE, OnVisible, &OnVisibleStruct) SINK_ENTRY_INFO (1, DIID_DWebBrowserEvents2, DISPID_QUIT, Quit, &QuitStruct) END_SINK_MAP () void Advise (); void UnAdvise (); READYSTATE GetReadyState (); void __ stdcall OnBeforeNavigate2 (IDispatch* pDisp, VARIANT* pvURL, VARIANT* pvFlags, VARIANT* pvTargetFrameName, VARIANT* pvPostData, VARIANT* pvHeaders, VARIANT_BOOL* pbCancel); void __ stdcall OnDocumentComplete (IDispatch* pDisp, VARIANT* pvURL); void __ stdcall OnNavigateError (IDispatch* pDisp, VARIANT* pvURL, VARIANT* pvTargetFrameName, VARIANT* pvStatusCode, VARIANT_BOOL* pbCancel); void __ stdcall OnQuit (); void __ stdcall OnVisible (VARIANT_BOOL bVisible); void __ stdcall Quit (); XBrowser* m_pBrowser; int m_cnt;} ; __ declspec (selectany) _ATL_FUNC_INFO XWebBrowser2EventsBase::BeforeNavigate2Struct = {CC_STDCALL, VT_EMPTY, 7, {VT_DISPATCH, VT_BYREF | VT_VARIANT, VT_BYREF | VT_VARIANT, VT_BYREF | VT_VARIANT, VT_BYREF | VT_VARIANT, VT_BYREF | VT_VARIANT, VT_BYREF | VT_BOOL}}; __ declspec (selectany) _ATL_FUNC_INFO XWebBrowser2EventsBase::DocumentComplete2Struct = {CC_STDCALL, VT_EMPTY, 2, {VT_DISPATCH, VT_BYREF | VT_VARIANT}}; __ declspec (selectany) _ATL_FUNC_INFO XWebBrowser2EventsBase::NavigateErrorStruct = {CC_STDCALL, VT_EMPTY, 5, {VT_BYREF | VT_BOOL, VT_BYREF | VT_VARIANT, VT_BYREF | VT_VARIANT, VT_BYREF | VT_VARIANT, VT_BYREF | VT_DISPATCH}}; __ declspec (selectany) _ATL_FUNC_INFO XWebBrowser2EventsBase:: OnQuitStruct = {CC_STDCALL, VT_EMPTY, 0, {NULL}}; __ declspec (selectany) _ATL_FUNC_INFO XWebBrowser2EventsBase:: OnVisibleStruct = {CC_STDCALL, VT_EMPTY, 1, {VT_BOOL}}; __ declspec (selectany) _ATL_FUNC_INFO XWebBrowser2EventsBase:: QuitStruct = {CC_STDCALL, VT_EMPTY, 0, {NULL}}; XEventSink:: : XEventSink (class XBrowser* a_pBrowser) {m_pBrowser = a_pBrowser;} XEventSink:: ~XEventSink () {UnAdvise ();} void XEventSink:: Advise () {if (FAILED (DispEventAdvise (m_pBrowser-> m_pIE, &DIID_DWebBrowserEvents2))) return; OutputDebugString ("Advise\n"); m_cnt = 0;} void XEventSink:: UnAdvise () {DispEventUnadvise (m_pBrowser-> m_pIE, &DIID_DWebBrowserEvents2); OutputDebugString ("UnAdvise\n");} READYSTATE XEventSink:: GetReadyState () {READYSTATE state = READYSTATE_UNINITIALIZED; if (m_pBrowser) m_pBrowser-> m_pIE-> get_ReadyState (&state); return state;} void XEventSink:: OnBeforeNavigate2 (IDispatch* pDisp, VARIANT* pvURL, VARIANT* pvFlags, VARIANT* pvTargetFrameName, VARIANT* pvPostData, VARIANT* pvHeaders, VARIANT_BOOL* pbCancel) {OutputDebugString (StringPrintf ("OnBeforeNavigate2 %d\n", m_cnt ++).c_str ());} void XEventSink:: OnDocumentComplete (IDispatch* pDisp, VARIANT* pvURL) {OutputDebugString (StringPrintf ("OnDocumentComplete %d\n", m_cnt ++).c_str ()); if (GetReadyState () == READYSTATE_COMPLETE) {OutputDebugString ("READYSTATE_COMPLETE\n"); m_pBrowser-> WaitDocument ();}} void XEventSink:: OnNavigateError (IDispatch* pDisp, VARIANT* pvURL, VARIANT* pvTargetFrameName, VARIANT* pvStatusCode, VARIANT_BOOL* pbCancel) {OutputDebugString (StringPrintf ("OnNavigateError %d\n", m_cnt ++).c_str ());} void XEventSink:: OnQuit () {OutputDebugString (StringPrintf ("OnQuit %d\n", m_cnt ++).c_str ()); m_pBrowser-> WaitDocument ();} void XEventSink:: OnVisible (VARIANT_BOOL bVisible) {OutputDebugString (StringPrintf ("OnVisible %d\n", m_cnt ++).c_str ());} void XEventSink:: Quit () {OutputDebugString (StringPrintf ("Quit %d\n", m_cnt ++).c_str ());}