Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to receive events in IE via <OBJECT> from ATL Simple Object

42 views
Skip to first unread message

LowRider2112

unread,
Mar 7, 2007, 5:10:00 PM3/7/07
to
REQUEST/PROBLEM:
==============
I need to know how to make an ATL "SimpleObject" fire events and have them
be received in IE 6+ using the <object> tag on a .htm page with JavaScript.

I see several posts about "UI controls" that fire events that can be handled
by a sink using IE's <object> element, but it doesn't apply to my requirement
in a few ways and now I am questioning myself if this really can be done
without a "true UI control."

MY CODE SAMPLES
==============

IDL snipet:
-----------

[
uuid(B7D91A4C-50D2-4ccd-8BEB-EA9B2AF37A60),
helpstring("My Test Events")
]
dispinterface IMyTestEvents
{
properties:
methods:
[ id(1) ] void OnTestEvent([in] long nSomething);
};

...

[
uuid(B1234A37-C3D2-4EA1-BC14-054BC2F22807),
helpstring("MyTestEventObject"),
appobject
]
coclass MyTestEventObject
{
...
[default, source] dispinterface IMyTestEvents;
};

HTML page:
--------------

<OBJECT id="idMyTestEventObject"
CLASSID="CLSID:B1234A37-C3D2-4EA1-BC14-054BC2F22807"
HEIGHT="1"
WIDTH="1"
TYPE="application/x-oleobject">
</OBJECT>

<script for="idMyTestEventObject" language="javascript">

function idMyTestEventObject::OnTestEvent( nSomething )
{
alert("OnTestEvent: " + nSomething );
}

</script>


COMMENTS
============
When I invoke a method in the ATL .dll ("the source") that fires the event,
nothing happens in IE. Stepping through the debugger I can see in the ATL
source that walking the Connection Point Container list for Connection Points
of my IMyTestEvents type, it does NOT find any. It is like IE does not setup
the "advise" link, which is why I think the issue is something I'm not doing
right in IE.

I have also tried using the "attachEvent" method with normal function
signatures (no double colon) and had no success either.

Please remember there is no .net here, just COM and HTML plumbing here.

Thanks so much for your time.

REFERENCES:
http://support.microsoft.com/kb/555687
(searched this forum for "events" with no resolution)

LowRider2112

unread,
Mar 8, 2007, 7:04:16 PM3/8/07
to
PROBLEM SOLVED!!!
"How To Enable ActiveX Control Event Handling on a Web Page"
http://support.microsoft.com/?id=200839

:-)))))

Gourab

unread,
Mar 28, 2007, 7:14:00 AM3/28/07
to
Hi LowRider2112,
Even I am facing the same problem, after refering that page I have derived
my class from the IProvideClassInfo2Impl class.

the html code I am using is as below:

<OBJECT id="idMyTestEventObject"
CLASSID="CLSID:95CF9ECA-5F83-4CD0-AEBD-C819CCD74B58"


HEIGHT="1"
WIDTH="1"
TYPE="application/x-oleobject">
</OBJECT>

<script for="idMyTestEventObject" language="javascript">

var WScript;
WScript = new ActiveXObject("WScript.Shell");
WScript.Run("E:\\test1.js")
</script>


// JScript source code
function btn_MyCallBack()
{
alert("Callback got invoked!");
}
var bt;
bt = WScript.CreateObject("MyObj.Button2","btn_");
...

Please point out what is missing here. Or can you share some working code
here?

Thanks in advance
Gourab

LowRider2112

unread,
Mar 28, 2007, 12:08:06 PM3/28/07
to
Here is a list of the steps I had to do on the IE side of things to get
events to work (I think you are specifically missing the "::" notation in
your event handlers):

1. The ActiveX component must implement the IProvideClassInfo and
IProvideClassInfo2 interfaces.

As the following article describes, this is accomplished by only a few lines
of ATL code:
http://support.microsoft.com/?id=200839

2. You must use an <OBJECT> element in your web page.

<OBJECT ID="myControl"
CLASSID="CLSID:3DCEB37D-5AD0-4e5a-B652-C07DAFF7AFBF"


HEIGHT="1"
WIDTH="1"
TYPE="application/x-oleobject">
</OBJECT>

No, "new ActiveXObject()" doesn't work.

3. You must use the "object::eventHandler" notation in a "SCRIPT FOR" block
in the same web page your <OBJECT> resides:

<script for="myControl" language="javascript">

function myControl::OnMyEventHandler( sSomeData )
{
// Handle event.
}

</script>

This notation was found in KB article:
http://support.microsoft.com/kb/555687


NOTE: This also works all dynamically using DHTML: I was able to
dynamically create an <OBJECT> element using createElement() with all the
above HTML, then attaching it to the DOM's <body> element using
appendChild(), and then dynamically attaching event handlers using
"myObject::attachEvent()". Please note in this context, if you use
attachEvent(), you do not need the double-colon myObject::Handler notation.
Furture beware that if you create an <OBJECT> using DHTML, before you can use
it, you must wait for the myObject.readyState property to be 4, only after
which can you call attachEvent(). To do so, I made a function that does a
setTimeout() call and just waits on the 4 == myObject::readyState and then
continues.

I hope this helps!

-LowRider2112

Gourab

unread,
Mar 29, 2007, 9:04:06 AM3/29/07
to
Thanks a lot for your response. With this method I could not proceed as I was
not able to call functions of the object. Actually I need to call some
functions and on return I would get back the event. I tried to call the
function in various ways but in vain. Could you guide how to make a call to
some functions for the same object from there.

Anyway today I was able to get the call back through WScript.CreateObject()
API. I was using VBScript. The code snippest is as below:

WScript.CreateObject("MyObject","btn_")
...
Sub btn_ReceivedCallback()
MsgBox ("Callback Received")
End Sub


Thanks again for your time,
gourab

0 new messages