This is a heads up for people developing ActiveX controls for IE. The problem was demonstrated on IE 7 but might be true on other browser versions.
If you embed an ATL based ActiveX control inside a web page and try to send/fire events to the script and find out that the events are not generated then you might have the following problem.
As a simple debug trace can demonstrate initiation of ActiveX controls and script on a web page is done synchronically by one thread.
At first, objects are created, then any global script code gets executed and only after that IConnectionPointContainerImpl Advise gets called to establish a connection between the connection point and a sink.
Now the problem is that if you call a member function of the ActiveX object in the global script and this function tries to generate events those events will never be generated since the advise function was not called yet.
A simple solution to the problem, although a little bit of a hack, is to make sure you never call ActiveX functions when the page initializes.
Instead you can use a timer event handler function and call the ActiveX functions from inside the timer event handler this will insure that advise gets called to register the event handlers before you call any ActiveX member functions.
//InitActiveX(); //-> PRB: un remarking this line will cause the advise function not to get called on time!!
var timerId = setTimeout('InitActiveX',1000); // this works because the advise function will get called before the timer event handler function gets executed!!
Note that even a time delay of 0 works because it still makes sure the function is not called directly from the global script.