I have developed a custom ActiveX control using the IDispatch interface and I'm trying to establish communication with JavaScript. The path from JavaScript to COM is functioning correctly; I can invoke a JavaScript function on my ActiveX object and receive an INVOKE call in my DLL.
In order to receive events on the JavaScript side, I am following guidance from this article:
Upon loading my test page, FindConnectionPoint and Advise are being called as expected. However, when I invoke the interface provided by Advise, it returns a success status message but no action is taken on the JavaScript side!
Here is the JavaScript code I am using to test event handling:
function FooActiveX::ReceiveMessage(msg)
{
alert(msg);
}
Interestingly, if I remove the code snippet above, the calls to FindConnectionPoint or Advise cease to occur, indicating that something is happening.
If you have any advice on how to debug this issue or suggestions for troubleshooting, it would be greatly appreciated. Thank you!
The interface definition file looks like this:
[
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;
}
}
EDIT: It appears that the issue may be related to the parameter in the ReceiveMessage method. Removing the "msg" parameter allows the alert box to display properly.