I've got a bit of a problem with my application using MSHTML. I have everything working except for the odd keystroke missing behavior when typing fast as mentioned in the subject line. I think it may have to do with the method I use to sink the events?
The details: my application is a separate program written in C++ and MFC in Visual Studio 2005. The program attaches to a currently running (independent) instance of Internet Explorer and gets the pointer to the IWebBrowser2
interface and passes it to an object of type CCmdTarget
:
class CHandler : public CCmdTarget
{
IWebBrowser2* m_pWebBrowser2;
DWORD m_dwBrowserCookie;
…
DECLARE_DISPATCH_MAP()
};
This class keeps track of what's happening in the browser. I sink the browser events with the following command:
LPUNKNOWN pUnkSink = GetIDispatch(FALSE);
retval = AfxConnectionAdvise((LPUNKNOWN)m_pWebBrowser2, DIID_DWebBrowserEvents2, pUnkSink, FALSE, &m_dwBrowserCookie);
If I comment out the AfxConnectionAdvise
, then no keystrokes are missed but no more events. If I leave it in I sink the events but miss the occasional keystroke if typing fast.
I know there are a number of ways of connecting to the events (AtlAdvise
, connection points), but this was the only one I could get working.
Any suggestions would be great!