【发布时间】:2014-10-26 04:11:35
【问题描述】:
我使用 IDispatch 接口编写了一个自定义的活动 X 控件,我想与 javascript 进行通信。我已成功使 javascript -> COM 路径正常工作;我可以在我的活动 x 对象上调用 javascript 函数并在我的 dll 中接收相应的 INVOKE 调用。
要在 javascript 端接收事件,我遵循本文中的建议:http://jeffcode.blogspot.com/2008/02/how-to-create-activex-control-that.html
当我加载我的测试页面时,我收到了对 FindConnectionPoint 的调用,然后是对 Advise 的调用,正如我所期望的那样。在Advise给出的接口上调用Invoke,得到成功状态信息,但是js端什么都没有发生!
这是我用来测试事件处理的 javascript 代码:
function FooActiveX::ReceiveMessage(msg)
{
alert(msg);
}
有趣的是,如果我删除它,我不会再接到 FindConnectionPoint 或 Advise 的调用,所以它正在做某事。
有关如何调试此问题或尝试的事情的任何建议都会非常有帮助。谢谢!
我的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 方法中的参数有关。如果我删除“msg”参数,警告框将正常显示。
【问题讨论】:
标签: javascript c++ com activex