Javascript experiencing issues with firing custom events for Active X control

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.

Answer №1

Realized the issue I was facing. When passing arguments to the method, they are given to Invoke as an array of VARIANTARG structures. Although I had assigned the value, I neglected to set the vt member of that structure, which specifies the type of the parameter. It's puzzling why invoke still returned an OK status.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When adding another Mesh, an error occurs in three.js stating: "Uncaught TypeError: Cannot read property 'center' of undefined - three.js:6754."

As I delve into coding with JS, I decided to experiment with Three.js. Everything was running smoothly until I included the line scene.add(my_square);. From that point on, my code failed to work and displayed the following error: Uncaught TypeError: Canno ...

Increasing space at the top with heading

As I scroll down, the header on my website remains in a static position and disappears. However, when I scroll back up, the header reappears wherever the user is on the page. While this functionality works well, I have noticed that as I scroll all the way ...

Challenges arise when attempting to pinpoint distinct coordinates from within a spherical structure

I've recently started working with Three.js [r78] and I'm still a beginner in both Three.js and JavaScript in general. After some trial and error, I was able to cast a ray from a perspective camera at the center of a sphere with a radius of 500. ...

The jQuery function for AJAX does not properly validate the boolean value provided by the controller

I have a controller action that returns a boolean result to jQuery. [HttpGet] public ActionResult IsVoucherValid(string voucherCode) { bool result = false; var voucher = new VoucherCode(voucherCode); if(voucher.Status==0) ...

When the Button is clicked, scroll the element to the top position

I want to include an "ADD COMMENT" button on my page. When clicked, a form will be displayed for users to add comments. I would like the form to automatically scroll to the top position of the page so that users do not have to manually scroll down to vie ...

The value returned by EntityRecognizer.resolveTime is considered as 'undefined'

In my bot's waterfall dialog, I am utilizing the LuisRecognizer.recognize() method to detect datetimeV2 entities and EntityRecognizer.resolveTime() to process the response. Here is an example of how I have implemented it: builder.LuisRecognizer.recog ...

Scroll to the top on every Angular 5 route change

Currently, I am utilizing Angular 5 for my project. Within the dashboard interface, there are various sections with varying amounts of content. Some sections contain only a small amount of information, while others have large amounts of content. However, w ...

What manner must I understand this syntax?

After stumbling upon this code snippet online, I was left scratching my head: function cjsDetectionPlugin() { return { name: 'cjs-detection', moduleParsed({ id, meta: { commonjs: { isCommonJS } } }) { ...

Using the v-for directive before applying the Vue directive

I need help with displaying images in a carousel from data fetched via Firebase. I have created a directive, but the problem lies with the v-for loop. The directive is executed before the v-for loop, resulting in no items in the carousel. Directive: di ...

Typescript: Defining the correct return type for resolved parameters in promises

Exploring the world of TypeScript, I recently attempted to convert some basic JavaScript promise samples into TypeScript promises. While working on this conversion process, I encountered an issue that has left me puzzled and unable to find a solution even ...

Is there a way to verify if type T exists within the parameter pack Ts...?

I am looking to create a function that will return true if T is one of Ts... template<class T, class... Ts> bool check_if_one_of<T, Ts...>(); For instance, calling check_if_one_of<int, double, int, float> should yield true, while check_ ...

What is the method for incorporating an async middleware into a router route?

I am currently setting up routes for an express router in my project. I have a validator that deals with promises, requiring me to use await in the code. Here is how it looks: constructor() { this.router = express.Router(); this.router.use(express. ...

Ways to resolve Error: CastError: The casting to ObjectId was unsuccessful for the value (string type) at the specified path "_id" in the model

Here is my current code snippet for the /api/students/id route: router.get('/:id',asyncHandler(async(req,res)=>{ const student = await Student.findById(req.params.id) if(student){ res.json(student) ...

The performance of three.js PointsMaterial is sluggish when utilizing large sprites or shapes, causing a decrease in overall

Currently, I am handling a point cloud with approximately 60,000 vertices. Interestingly, when I view the cloud at a smaller scale, performance remains acceptable. However, as soon as I zoom in and larger sprites/plans/points become visible on the screen, ...

Interactive Sideways Navigation Bar

showcases a sleek horizontal scrolling menu on mobile devices. I aim to replicate this functionality for a website I'm redesigning that features extensive navigation elements. Key Features: Left and right scroll button options Centered list item op ...

Transitioning from one CSS id to another during page loading

Wondering how to fade in one CSS id on page load and then smoothly transition to another after a few seconds? Here are the ids: #background { background: url("images/am_photography_bg.jpg") no-repeat center -25px fixed; background-size: 100%; ...

Issues loading resource: bundle.js generates successfully in NodeJS and React app, however, error 404 occurs

I am currently working on a simple practice project where I have some initial content (a '...' string) in the JS environment. My goal is to load React after the JS environment loads and replace the content with a 'hello react' string wi ...

Issue arises during compilation of DLL using Intel compiler

I am currently attempting to compile a DLL from the console, without relying on any IDE, and have encountered the following error: Here is the code I have written: test_dll.cpp #include <windows.h> #define DLL_EI __declspec(dllexport) BOOL WINAPI ...

Issues with implementing custom jQuery show/hide functionality for div elements in ASP.Net

My master page includes a script manager and JavaScript/jQuery code as shown below: <asp:ScriptManager ID="SM" runat="server" EnablePartialRendering="true"> <Scripts> <asp:ScriptReference Path="~/Scripts/jquery-1.7.2.min.js" Scr ...

Rearranging the position of the line continuations (') utilized in macros through the clang-format program

One of my code snippets involves the use of various Macros, some of which are quite lengthy. Before applying clang-format, here is an example: #define assertionTriggersExit { \ std::cout.flush(); \ std::cerr.flush(); \ ...