Shoutbox

COM Events - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: COM Events (/showthread.php?tid=70760)

COM Events by omahena on 01-16-2007 at 09:30 PM

Hi guys,

I have been looking for a way to register my script to handle events fired by a COM object.

In HTML JavaScript this is quite simple and there are many ways to do this. I expected that something like this would work:

code:
var SomeObject = new ActiveXObject("AppID.ClsID");
SomeObject.OnSomeEvent = EventHandlerFunc;

...

function EventHandlerFunc(EvtParam1)
{
}


but that doesn't work. I also tried using the GetRef function and some other methods. This article seemed to give some good pointers. Maybe this will inspire somebody.

http://msdn2.microsoft.com/en-us/library/ms974564.aspx

I think out of all the methods the ConnectObject() function seems the right way to go. I have a feeling that something similar is used for MsgPlus events due to the automagic-like function names. The bummer is that I cannot find a way to call this function.

Any ideas? :|

RE: COM Events by omahena on 01-16-2007 at 10:19 PM

OK... That was silly. (A) It seems that only this particular COM object misbehaved. COM Events can be handled as I expected:

code:
function OnEvent_Initialize(MessengerStart)
{
  var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  xmlHttp.onreadystatechange = ORSC;
  Debug.Trace("Init complete.");
}

function ORSC()
{
  Debug.Trace("onreadystatechange");
}

Thanks for reading. And thanks to CoolDuDe_i06 for inspiring me with the gmail script.
RE: COM Events by deAd on 01-16-2007 at 10:55 PM

That kind of event is scripted into the com object and isn't always the usable one. For standard events:

code:
var pActivex;
function OnEvent_Intialize(bMessengerStart){
pActivex = new ActiveXObject("MyProject.Control");
fnEventHandler();
}
var fnEventHandler = function(){
pActivex::MyEventName = function(){
// do my event stuff
}
}
or something along those lines. :P
RE: COM Events by omahena on 01-16-2007 at 11:11 PM

Thanks for your reply. I didn't even realize that what you wrote is valid JScript. :D

I always used the event handlers in this way:

code:
var pActivex;

function OnEvent_Intialize(bMessengerStart)
{
  pActivex = new ActiveXObject("MyProject.Control");
  pActivex.MyEventName = fnEventHandler;
}

function fnEventHandler()
{
  // do my event stuff
}

I think I must have neglected to implement some interface in my COM object that I tried to use from the script. I'll figure that out tomorrow. |-)

I'll verify everything and report back if it works.