Handle VC++ ATL COM Event in Java Script ?? [modified]
-
How to handle COM Events in Java script How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj
modified on Tuesday, April 29, 2008 2:43 AM
-
How to handle COM Events in Java script How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj
modified on Tuesday, April 29, 2008 2:43 AM
You can call JavaScript functions from C++ using the IHTMLDocument::get_Script[^] function.
Steve
-
You can call JavaScript functions from C++ using the IHTMLDocument::get_Script[^] function.
Steve
Hi Steve You took the question wrong ... The question is how to handle events in Java script which are fired from ATL COM I am able to call COM interface methods in java scripts but not able to handle events fired from the same ATL COM Component and not "call java script functions in C++" with regards Abhiraj
-
Hi Steve You took the question wrong ... The question is how to handle events in Java script which are fired from ATL COM I am able to call COM interface methods in java scripts but not able to handle events fired from the same ATL COM Component and not "call java script functions in C++" with regards Abhiraj
You haven't explained properly. How is the ATL COM object hosted? If it's hosted on the page you can simply handle it like any other event in HTML. It it's not on the page you would sink the events with an interface implemented in C/C++ and the methods would delegate to the web page as described in my previous post.
Steve
-
You haven't explained properly. How is the ATL COM object hosted? If it's hosted on the page you can simply handle it like any other event in HTML. It it's not on the page you would sink the events with an interface implemented in C/C++ and the methods would delegate to the web page as described in my previous post.
Steve
Hi Steve I would like to change my question... How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj
-
Hi Steve I would like to change my question... How to use ATL COM in java script and handle COM event in java script if the ATL COM is developed in C++ Abhiraj
Firstly, I’ll assume you’re embedding a COM object in a HTML page (you haven’t explicitly stated this). Here’s what my page looks like:
<html>
<head>
<title>CallMe</title>
</head>
<body>
<object id="my_obj" classid="clsid:7815559F-240E-406E-A0F0-974B7272C65F">
</object>
<script type="text/javascript" for="my_obj" event="Hello">
window.alert("Hello!");
</script>
<input type="button" value="Call into COM object" onclick="my_obj.CallMe();" />
</body>
</html>Note that I used MSVC6, but other versions will have equivalent functionality. You’ll have to use connection points to implement an outgoing interface. Here’s the IDL of my project:
// HostMe.idl : IDL source for HostMe.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (HostMe.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(4E413D85-21DC-48FC-AD65-B8635B74CBFF),
dual,
helpstring("IHostMeObj Interface"),
pointer_default(unique)
]
interface IHostMeObj : IDispatch
{
[id(1), helpstring("method CallMe")] HRESULT CallMe();
};
[
uuid(9598F3A4-B8DE-4BA8-9AE1-90903ED9EF38),
version(1.0),
helpstring("HostMe 1.0 Type Library")
]
library HOSTMELib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(5C211D24-97D2-4AA1-AB93-EE605DC97614),
helpstring("_IHostMeObjEvents Interface")
]
dispinterface _IHostMeObjEvents
{
properties:
methods:
[id(1), helpstring("method Hello")] void Hello();
};
[
uuid(7815559F-240E-406E-A0F0-974B7272C65F),
helpstring("HostMeObj Class")
]
coclass HostMeObj
{
[default] interface IHostMeObj;
[default, source] dispinterface _IHostMeObjEvents;
};
};It’s also important to implement the IProvideClassInfo and IProvideClassInfo2 interfaces or the callbacks will not work. The following articles (on the Wayback Machine, as the originals seem to have been deleted) may help: http://web.archive.org/web/20060915111734/http://msdn.microsoft.com/archive/en-us/dnarguion/html/drgui082399.asp[^]
-
Firstly, I’ll assume you’re embedding a COM object in a HTML page (you haven’t explicitly stated this). Here’s what my page looks like:
<html>
<head>
<title>CallMe</title>
</head>
<body>
<object id="my_obj" classid="clsid:7815559F-240E-406E-A0F0-974B7272C65F">
</object>
<script type="text/javascript" for="my_obj" event="Hello">
window.alert("Hello!");
</script>
<input type="button" value="Call into COM object" onclick="my_obj.CallMe();" />
</body>
</html>Note that I used MSVC6, but other versions will have equivalent functionality. You’ll have to use connection points to implement an outgoing interface. Here’s the IDL of my project:
// HostMe.idl : IDL source for HostMe.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (HostMe.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(4E413D85-21DC-48FC-AD65-B8635B74CBFF),
dual,
helpstring("IHostMeObj Interface"),
pointer_default(unique)
]
interface IHostMeObj : IDispatch
{
[id(1), helpstring("method CallMe")] HRESULT CallMe();
};
[
uuid(9598F3A4-B8DE-4BA8-9AE1-90903ED9EF38),
version(1.0),
helpstring("HostMe 1.0 Type Library")
]
library HOSTMELib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(5C211D24-97D2-4AA1-AB93-EE605DC97614),
helpstring("_IHostMeObjEvents Interface")
]
dispinterface _IHostMeObjEvents
{
properties:
methods:
[id(1), helpstring("method Hello")] void Hello();
};
[
uuid(7815559F-240E-406E-A0F0-974B7272C65F),
helpstring("HostMeObj Class")
]
coclass HostMeObj
{
[default] interface IHostMeObj;
[default, source] dispinterface _IHostMeObjEvents;
};
};It’s also important to implement the IProvideClassInfo and IProvideClassInfo2 interfaces or the callbacks will not work. The following articles (on the Wayback Machine, as the originals seem to have been deleted) may help: http://web.archive.org/web/20060915111734/http://msdn.microsoft.com/archive/en-us/dnarguion/html/drgui082399.asp[^]
Hi Steve I have implemented the IProvideClassInfo and IProvideClassInfo2 interfaces for the callbacks and the callback are working fine Now the issue is even if I fire Event from ATL COM once , its shown more than once on the web page as if i have fired event from ATL COM many times and everytime the count is getting increased .... I have used this ATL Component in VB also , in VB its working fine if event is fired once the event is shown once and not more than that... Here is the code snippet ...... MessageBox(NULL,TEXT("Fire Event Reached"),TEXT("OK"),MB_OK); hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL); MessageBox(NULL,TEXT("Fire Event Complete"),TEXT("OK"),MB_OK); ......... I have used two message boxes just for the sake for debugging... Now in VB whenever there is event i have shown a msg box so once event is fired only 3 messages boxes comes one after the other 1. Fired Event Reached 2. Event Message Box (When "pConnection->Invoke" is fired) 3. Fire Event Complete Now in Internet Explorer its different.. whenever event is fired by ATL COM Event Message Box is shown many times in the Internet Explorer and everytime the count is getting increased What can be the problem... with regards Abhiraj
-
Hi Steve I have implemented the IProvideClassInfo and IProvideClassInfo2 interfaces for the callbacks and the callback are working fine Now the issue is even if I fire Event from ATL COM once , its shown more than once on the web page as if i have fired event from ATL COM many times and everytime the count is getting increased .... I have used this ATL Component in VB also , in VB its working fine if event is fired once the event is shown once and not more than that... Here is the code snippet ...... MessageBox(NULL,TEXT("Fire Event Reached"),TEXT("OK"),MB_OK); hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL); MessageBox(NULL,TEXT("Fire Event Complete"),TEXT("OK"),MB_OK); ......... I have used two message boxes just for the sake for debugging... Now in VB whenever there is event i have shown a msg box so once event is fired only 3 messages boxes comes one after the other 1. Fired Event Reached 2. Event Message Box (When "pConnection->Invoke" is fired) 3. Fire Event Complete Now in Internet Explorer its different.. whenever event is fired by ATL COM Event Message Box is shown many times in the Internet Explorer and everytime the count is getting increased What can be the problem... with regards Abhiraj
Why are you firing the event manually using
IDispatch::Invoke
. The ATL wizard generates that code for you when you select the “Implement Connection Point…” option in the IDE.Steve
-
Why are you firing the event manually using
IDispatch::Invoke
. The ATL wizard generates that code for you when you select the “Implement Connection Point…” option in the IDE.Steve
I am not firing the event manually.. i am using the code generated by the ATL Wizard as such.. For firing event from worker thread .... microsoft has given link to be implemented for the same thats the only change i have done and rest of the code i have not touched... with regards Abhiraj
modified on Wednesday, May 7, 2008 12:27 AM