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)
:-)))))
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
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
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