IE BHO - DISPID_FILEDOWNLOAD being called for page loads? <p>I am implementing an Internet Explorer Browser Helper Object that should catch the <strong>DISPID_FILEDOWNLOAD</strong> event.</p> <p>I first implemented this in C# which worked great except that I also need the cookies that go with the URL so need to call InternetGetCookiesEx. As .NET runs in it's own process it does not return me the session cookies so is no good.</p> <p>I then wrote a quick test DLL in C++ so that it is loaded into the same process as IE which works great for the cookies but I now have a new problem:</p> <p>I am getting calls to <strong>DISPID_FILEDOWNLOAD</strong> in my Invoke function for each page load when I only want them for an actual download.</p> <p>In the C# version I only got a call to WebBrowser.FileDownload for an actual download but it seems that the C++ version is sending a DISPID_FILEDOWNLOAD even for each page load.</p> <pre><code>STDMETHODIMP CIEHlprObj::Invoke( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr ) { USES_CONVERSION; if (!pDispParams) return E_INVALIDARG; LPOLESTR lpURL = NULL; m_spWebBrowser2-&gt;get_LocationURL(&amp;lpURL); int i = 0; switch (dispidMember) { case DISPID_BEFORENAVIGATE2: case DISPID_BEFORENAVIGATE: sCurrentFile=NULL; if (pDispParams-&gt;cArgs &gt;= 5 &amp;&amp; pDispParams-&gt;rgvarg[5].vt == (VT_BYREF | VT_VARIANT)) { CComVariant varURL(*pDispParams-&gt;rgvarg[5].pvarVal); varURL.ChangeType(VT_BSTR); char* myStr = OLE2T(varURL.bstrVal); if (myStr) { sCurrentFile = AllocateString(myStr); sCurrentFileW = varURL.bstrVal; } } break; case DISPID_FILEDOWNLOAD: // CALLED FOR EACH PAGE LOAD! if(sCurrentFile) { TCHAR cookies[8192]; DWORD size = 8192; BOOL ret = InternetGetCookieEx(sCurrentFile, 0, cookies, &amp;size, INTERNET_COOKIE_HTTPONLY, 0); ::MessageBox(0, sCurrentFile, "Downloading called multiple times!!", MB_OK); } break; default: break; } return S_OK; } </code></pre> <p><strong>Is there some filter that needs checking somewhere to know if a DISPID_FILEDOWNLOAD event relates to a file load or an actual file download?</strong></p> <p>Many thanks</p> <p><strong>UPDATE:</strong></p> <p>On closer inspection it seems that the C# managed code version is actually doing the same, I just didn't notice it the firs time around.</p> <p>It seems that the FileDownload event is being called in the following circumstances:</p> <ol> <li>New window / tab opened</li> <li>New domain connected to (maybe a new keep-alive connection?)</li> <li>An actual download</li> </ol> <p>Obviously I only want the even on the actual download event.</p>