Handling ATL/ActiveX events from within JavaScript

匆匆过客 提交于 2019-12-03 21:46:19

I figured it out by looking at the Circ sample project that comes with VS2010. Turns out that (at least in my case) the ATL event wizard didn't update the IDL for the dispatch interface. Life was good once I updated the dispinterface section of the IDL file from this:

dispinterface _IMyControlEvents
{
    properties:
    methods:
};

To this:

dispinterface _IMyControlEvents
{
    properties:
    methods:
        [id(1)] void Connected();
        [id(2)] void Disconnected();
        [id(3)] void Authenticated();
};

Once I did that, I was able to get the various different event handling syntaxes to work.

First, all the examples I see from MSDN use "JScript" as the language, not "javascript", but I don't know if that makes a difference (perhaps both are accepted, but technically MS's implementation of ECMA is JScript, I believe).

As a variation on your method 3, maybe try specifying the EVENT attribute to the script:

<script for="MyControl" EVENT="Connected()" language="JScript">
  onConnected();
</script>

<script for="MyControl" EVENT="Disconnected()" language="JScript">
  onDisconnected();
</script>

<script for="MyControl" EVENT="Authenticated()" language="JScript">
  onAuthenticated();
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!