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

  • Home
  • SEARCH
  • 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 6178327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:26:13+00:00 2026-05-24T00:26:13+00:00

I’m writing an NPAPI plugin. In C++ code, I can’t create a JS object

  • 0

I’m writing an NPAPI plugin. In C++ code, I can’t create a JS object using NPAPI. I tried this method:

Foo.js

function Foo(p)
{

   this.a=p;
}

Foo.prototype.get=function()
{
   return this.a;
}

C++ code (I want to create the Foo object. Just link what we can do in JS . var s=new Foo(2);)

    int newJSObject(const NPP instance,const NPNetscapeFuncs* npnfuncs,const string    objectName,
      const NPVariant* args,const int argsCount,NPVariant& result)
   {

       int status;

       NPObject *winobj;
       npnfuncs->getvalue(instance,NPNVWindowNPObject,&winobj);

       NPVariant npJS;
       NPIdentifier npJSId=npnfuncs->getstringidentifier(objectName.c_str());

       status=npnfuncs->getproperty(instance,winobj,npJSId,&npJS);

       NPObject* npObjJS = NPVARIANT_TO_OBJECT(npJS);

       NPVariant npPrototype;
       NPIdentifier npPrototypeId=npnfuncs->getstringidentifier("prototype");
       status=npnfuncs->getproperty(instance,npObjJS,npPrototypeId,&npPrototype);

       NPObject* npObjPrototype = NPVARIANT_TO_OBJECT(npPrototype);


       NPVariant npJSConstructor;
       NPIdentifier npJSConstructorId=npnfuncs->getstringidentifier("constructor");

       status=npnfuncs->invoke(instance,npObjPrototype,npJSConstructorId,
         args,argsCount,&npJSConstructor);

    /*
    *   destroy memory
    * */
       npnfuncs->releaseobject(winobj);
       npnfuncs->releasevariantvalue(&npJS);
       npnfuncs->releasevariantvalue(&npJSConstructor);

       result=npJS;

       return status;
    }




    NPVariant jsFoo1;
    NPVariant arg;
    DOUBLE_TO_NPVARIANT(2,arg);
    NPVariant prams[]={arg};
    newJSObject(instance,npnfuncs,"Foo",prams,sizeof(prams)/sizeof(prams[0]),jsFoo);

    NPVariant jsFoo2;
    NPVariant arg;
    DOUBLE_TO_NPVARIANT(3,arg);
    NPVariant prams[]={arg};
    newJSObject(instance,npnfuncs,"Foo",prams,sizeof(prams)/sizeof(prams[0]),jsFoo);

But if we return jsFoo1 and jsFoo2 to JS code, then we call Fooxxx.get(). Both jsFoo1 and jsFoo2 is 3.
I know the problem is “constructor”

Can anyone give me another method the create the JS object in C++ using NPAPI?

  • 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-24T00:26:14+00:00Added an answer on May 24, 2026 at 12:26 am

    NPN_Construct doesn’t seem to work on browser objects, so there is no direct way to do what you want. What you could do, however, is make a javascript function to create the object for you and return it; you could even use NPN_Evaluate to inject it automatically into the page.

    something like this:

    function __create_object_2_params(obj, param1, param2) {
        return new obj(param1, param2);
    }
    

    FireBreath uses some similar tricks in places.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.