Active X控件自定义事件无法在Javascript中触发

Active X控件自定义事件无法在Javascript中触发

问题描述:

我已经使用IDispatch接口编写了一个自定义活动X控件,我希望使用JavaScript进行通信。我已经成功地获得了javascript - > COM路径的工作;我可以在我的活动x对象上调用一个javascript函数,并在我的dll中接收相应的INVOKE调用。Active X控件自定义事件无法在Javascript中触发

接收事件的JavaScript端,我下面这篇文章中的建议:http://jeffcode.blogspot.com/2008/02/how-to-create-activex-control-that.html

当我打开我的测试页,我接到一个电话,以FindConnectionPoint,然后打电话告知,我会期望。当我在Advise给出的接口上调用Invoke时,我得到了一个成功状态消息,但js一方没有任何反应!

这是我使用来测试事件处理的JavaScript代码:

function FooActiveX::ReceiveMessage(msg) 
{ 
    alert(msg); 
} 

有趣的是,如果我删除,我没有得到FindConnectionPoint来电或劝了,所以它做什么。

有关如何调试此问题或尝试尝试的任何建议将非常有帮助。谢谢!

我的IDL接口定义文件看起来是这样的:

[ 
uuid("1bf6bb1a-3232-11e4-a195-a6c5e4d22fb7"), 
version(1.0), 
] 
library FooControlLib 
{ 
interface IFooControl; 
dispinterface DFooControlEvents; 

importlib("stdole2.tlb"); 

[ 
    uuid("1bf6bb1a-3232-11e4-a195-a6c5e4d22fb8"), 
    hidden 
] 
dispinterface DFooControlEvents 
{ 
    properties: 
    methods: 
     [id(DISPID_RECEIVEMESSAGE)] void ReceiveMessage([in] BSTR msg); 
} 

[ 
    odl, 
    dual, 
    uuid("1bf6bb1a-3232-11e4-a195-a6c5e4d22fb9"), 
    oleautomation 
] 
interface IFooControl : IDispatch 
{ 
    [id(DISPID_SENDMESSAGE)] HRESULT SendMessage([in] BSTR msg); 
} 

[ 
    uuid("1bf6bb1a-3232-11e4-a195-a6c5e4d22fc0") 
] 
coclass FooControl 
{ 
    [default] interface IFooControl; 
    [source, default] dispinterface DFooControlEvents; 
} 
} 

编辑:看来这个问题是关系到在ReceiveMessage方法的参数。如果我删除了“味精”参数,警告框将正确显示。

发现我的问题。该方法的参数作为VARIANTARG结构的数组传递给Invoke。我已经设置了该值,但不是该结构的vt成员,它标识了参数的类型。我不知道为什么invoke返回OK状态。