Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:21:12+00:00 2026-05-26T04:21:12+00:00

I want to pass JavaScript objects (JSON and function objects) into my ActiveX control.

  • 0

I want to pass JavaScript objects (JSON and function objects) into my ActiveX control. Ideally, I could manipulate JavaScript objects (e.g. reading or modifying JSON) and perform JavaScript function calls from within the ActiveX control (using C++). Is any of this possible, or do I have to settle for passing strings?

For example, here is what I can do in Firefox. Notice that I have a reference to a JSON object, and I can also perform JavaScript function calls:

NPString jsonToString(NPP instance, NPObject* json)
{
    NPVariant result;
    NPVariant arg;
    NPIdentifier identifier;

    /* Get the global object */
    NPObject* windowObj = NULL;
    g_NPNFuncs.getvalue(instance, NPNVWindowNPObject, &windowObj);

    /* Get JSON object */
    identifier = g_NPNFuncs.getstringidentifier("JSON");
    g_NPNFuncs.getproperty(instance, windowObj, identifier, &result);
    NPObject* jsonObj = NPVARIANT_TO_OBJECT(result);

    /* Call stringify */
    identifier = g_NPNFuncs.getstringidentifier("stringify");
    OBJECT_TO_NPVARIANT(json, arg);
    g_NPNFuncs.invoke(instance, jsonObj, identifier, &arg, 1, &result);

    return NPVARIANT_TO_STRING(result);
}

Edit – Here’s the solution I came up with:

IDL file:

[id(TEST_ID)] BSTR Test(BSTR data, IDispatch* function);

Dispatch map:

DISP_FUNCTION_ID(CApp, "test", TEST_ID, Test, VT_BSTR, VTS_BSTR VTS_DISPATCH)

Interface function:

BSTR Test(BSTR data, IDispatch* function)

Calling the JavaScript function object:

VARIANTARG args[1];
args[0].vt = VT_BSTR;
args[0].bstrVal = _bstr_t(dataStr).GetBSTR();

DISPPARAMS params;
params.cArgs = 1;
params.cNamedArgs = 0;
params.rgvarg = args;

HRESULT hresult = function->Invoke(0, IID_NULL,
    LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, NULL, NULL, NULL);

Calling IDispatch::Invoke with a DISPID of 0 seems to work for invoking a function object. However, to call a method of an object, you have to get the corresponding DISPID first, as Taxilian said. GetNextDispID should work for that (first QueryInterface for IDispatchEx; casting to IDispatchEx seems to work too, but maybe isn’t safe).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:21:13+00:00Added an answer on May 26, 2026 at 4:21 am

    Wow, I’m aparently not very bright today because I just wrote up an answer completely missing the part where you said the npapi plugin code was an example =]

    so, to answer the correct question, yes you can. The type in ActiveX that closest correlates to NPObject is IDispatch (or IDispatchEx). Rather than having a GetProperty, SetProperty, and Invoke, you merely call Invoke and tell it if it should get a property, set a property, or invoke a method. You’ll first have to query to get the DISPID of the member in question; similar to a NPIdentifier, DISPID is a mapping between a string and a number.

    If you haven’t seen it you should really look at FireBreath, which provides an abstraction to allow you to write a plugin that works on both NPAPI and ActiveX with the same codebase. It has a wrapper to allow it to use IDispatch objects that you’ll probably find useful as an example.

    So long story short, you can use JS objects pretty much the same way you could with a NPObject by using IDispatch (or even better, IDispatchEx). Most things from javascript come through as a IDispatchEx, but occasionally I’ve seen instances where IDispatch failover support was needed.

    Hope it helps, and I hope my initial response (before I re-read your question) didn’t throw you off.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass a date object into a function and determine what the
I want to pass an object array to the setTimer function in Javascript. setTimer(foo(object_array),1000);
All i want is to pass a HTML (DOM object) from javascript to Actionscript.
I want to pass in the tType of a class to a function, and
I have a Javascript object that I want to pass in more parameters, but
Is there a way to pass JSON objects to the front end of a
I'm trying to pass some data to javascript in my view. I only want
I want to pass an integer value to a form in .Net so that
I want to pass an int list (List) as a declarative property to a
I want to pass an enum value as command parameter in WPF, using something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.