Internet Explorer ATL ActiveX event not firing (IConnectionPointContainerImpl Advise not called on time)

by APIJunkie 1/25/2008 10:54:00 AM
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.

Example:

Lets assume we have a init function in the JavaScript script that does some ActiveX initialization.

function InitActiveX()

{

MyActiveXObj.Myfunction(parameters);

}

//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.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C++ | PRB | ActiveX | ATL

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author

My name is Bacon…James Bacon.

I am an API wars veteran I was wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

E-mail me Send mail


Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in