I've got a really weird problem with my application; it works on some pc's, and it doesn't on some others. What I've got:
A Visual C# 2005 console application with references to MSHTML and SHDOCVW. I use mshtml to get a list of currently open browser windows, and attach events to it to edit the list when a new browser window is created or closed. I attach a documentComplete event to each open browser window and handle it the event there (let's say it prints out the url where is navigated to). So when I run this program, it should detect when I open a new browser window, when I close one, and it should print out the url of a site when it is done loading it.
And there's my problem. On a few pc's, it all works perfectly. But on one other I tried it on, the documentcomplete event refuses to fire. I've tried many things, but I just can't get it to fire. On google I read about bugs that the visible property has to be set to true in order for the event to fire, but I've checked that; and it is set to true! Apart from that, why would it work on a few pc's, and not work on some others
On two pc's I tried it on it worked: one Vista and one XP SP2 pc, one running IE7 en one running IE6.
The pc it didn't work on runs Windows 2000 and IE6.
Does anyone know how to fix this, or does anyone know a workaround to this problem
Thanks in advance,
Floris
public class GetIE
{
private DShellWindowsEvents_WindowRegisteredEventHandler registerHandler; private DShellWindowsEvents_WindowRevokedEventHandler revokeHandler; private DWebBrowserEvents2_DocumentCompleteEventHandler docCompleteHandler; private ShellWindows shellWindows; private ArrayList windowsList; public GetIE(){
registerHandler =
new DShellWindowsEvents_WindowRegisteredEventHandler(shellWindows_WindowRegistered);revokeHandler =
new DShellWindowsEvents_WindowRevokedEventHandler(shellWindows_WindowRevoked);docCompleteHandler =
new DWebBrowserEvents2_DocumentCompleteEventHandler(ie_DocumentComplete);windowsList =
new ArrayList();}
public void Run(){
shellWindows =
new ShellWindowsClass();shellWindows.WindowRegistered += registerHandler;
shellWindows.WindowRevoked += revokeHandler;
copyWindowsList();
}
private void copyWindowsList(){
ArrayList c_windowsList = (ArrayList)windowsList.Clone();windowsList.Clear();
foreach (WebBrowser ie in shellWindows) // A SHDOCVW WebBrowser. NOT a System.Windows.Forms one!{
windowsList.Add(ie);
if (!c_windowsList.Contains(ie)){
ie.DocumentComplete += docCompleteHandler;}
}
}
private void shellWindows_WindowRegistered(int lCookie){
Console.WriteLine("\nNew window registered. lCookie = " + lCookie.ToString());copyWindowsList();
printWindowsList();
}
private void shellWindows_WindowRevoked(int lCookie){
Console.WriteLine("\nWindow revoked. lCookie = " + lCookie.ToString());copyWindowsList();
printWindowsList();
}
private void ie_DocumentComplete(object pDisp, ref object URL){
string mode; Console.WriteLine("DOCUMENTCOMPLETE EVENT: " + URL.ToString()); }}

documentcomplete event
FastRider30
Leon Mayne
I uninstalled visual studio 2003 and 2005 from a workstation, and the problem appears. I'm guessing that having any visual studio installed is required for the event to fire.
Unfortunately, I don't have any further explanation, nor do I have a decent solution for this problem :(
Jeff Sholl
I found the problem. Apparently, Visual Studio will install a Primary Interop Assembly (PIO) under Program Files/Microsoft.Net folder, called Microsoft.mshtml.dll. Unfortunately, it's not installed with windows / .net. This needs to be distributed with the executable or installed on the client machines.
It won't throw an exception from documentcomplete(), but it will throw one if you reference the corresponding htmldocument after documentcomplete is called.
Jon Langdon - MSFT
Will Merydith
Slion
Covi
I've the exact same problem. I've tried it on 3 machines running xp sp2, and documentComplete() does not fire on one of them. That machine doesn't have dev software installed... I'm not sure if that is the problem. Please post if you find a solution.
Medes_
This is really weird.. I also tried to run in on a few more pc's without VS and then on a few more with VS and indeed, on the pc's with VS it all works fine, and without VS everything works except the DocumentComplete event... Exactly the same as you experienced.
I really have no idea why and also have no idea how to fix it.. It just doesn't make sense that VS needs to be installed in order for one specific COM event to fire, where other events from the same COM DLL do fire, also without VS! The DLL ships with my program, it's exactly the same for every pc it runs on!
I'm very confused right now.. It would be really nice if someone from Microsoft would jump in now and tell us a solution. ;)
KamranZafar
Ernie Anderson
robinjam
You're right. It works when I copy the mshtml.dll locally.. But DocumentComplete is a SHDocVW event, not MSHTML. :/ And the MSHTML functions were working properly; enumerating all open windows, event whenever a window is created or revoked..
I don't understand why it works when I distribute mshtml with my programs, but at least it works.. That's the most important right now. ;)
Thanks!
Floris