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 8333563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:04:40+00:00 2026-06-09T03:04:40+00:00

I have this getValue method + NPclass methods: static bool hasmethod(NPObject *npobj, NPIdentifier name)

  • 0

I have this getValue method + NPclass methods:

static bool hasmethod(NPObject *npobj, NPIdentifier name)
{
    return true;
}
static NPObject* allocate (NPP npp, NPClass *aClass)
{
    return  browser-> createobject(npp, aClass);
}
static bool hasProperty(NPObject *npobj, NPIdentifier name)
{
     return true;
}
static bool getProperty (NPObject *npobj, NPIdentifier name, NPVariant *result)
{
   if (!result) 
       return false;
   INT32_TO_NPVARIANT(50, *result);
   return true;
}
static void deallocate (NPObject *npobj)
{
   browser -> memfree(npobj);
}
static bool enumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count)
{
    return false;
}
static bool defaultInvoke(NPObject* obj, const NPVariant *args, uint32_t argCount,     NPVariant *result)
{
    if (!result) 
    return false;
    INT32_TO_NPVARIANT(42, *result);
    return true;
}
static bool setProperty (NPObject *npobj, NPIdentifier name, const NPVariant *value)
{
    return false;
}  
static void invalidate(NPObject *npobj)
{
}
static bool removeProperty (NPObject *npobj,NPIdentifier name)
{
    return false;
}
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
{
    if (! instance)
    {
        return NPERR_INVALID_INSTANCE_ERROR;
    }
struct NPClass class;
class.structVersion = NP_CLASS_STRUCT_VERSION;
class.construct = NULL;
class.deallocate = deallocate;
class.hasMethod = hasmethod;
class.getProperty= getProperty;
class.enumerate= enumerate;
class.removeProperty= removeProperty;
class.hasProperty = hasProperty;
class.invoke = pinvoke;
class.invokeDefault = defaultInvoke;
class.invalidate = invalidate;
class.setProperty = setProperty;
class.allocate = allocate;
if (variable == NPPVpluginScriptableNPObject)
{
    void **v = (void **)value;
    struct NPObject *object = NPN_CreateObject(instance, &class);
    NPN_RetainObject(object);
    *v = object;
    return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}

Here are the two other methods the class points to:

 bool hasmethod(NPObject *npobj, NPIdentifier name)
 {
     return true;
 }

static bool pinvoke(NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
    if (!result) 
    return false;
    INT32_TO_NPVARIANT(32, *result);
    return true;
}

Basically, I wanted the object to return 32 when anything was called just to test.

Here are my create & retain methods:

NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
{
    return browser->createobject(npp, aClass);
}

NPObject *NPN_RetainObject(NPObject *npobj)
{
    return browser->retainobject(npobj);
}

In my Javascript:

        <embed type="application/x-my-extension" id="pluginId">
            <script>
            var plugin = document.getElementById("pluginId");
            console.log(plugin.something);

The window is drawn on the page, but the console outputs undefined.
Help would be greatly appreciated. Thanks!

UPDATE: Georg suggested that the browser was crashing due to infinite recursion with my allocate method. Here is the new one:

 void* NPN_MemAlloc(uint32_t size)
 {
     return browser->memalloc(size);
 }
 static NPObject* allocate (NPP npp, NPClass *aClass)
 {
   NPObject* object = (NPObject*)NPN_MemAlloc(sizeof(NPObject));
   if (!object)
   {
    return NULL;
   }
   memset(object, 0, sizeof(NPObject));
   return object;
 }

The plugin still crashes.

Update 2: I made the object Instance specific

typedef struct PluginInstance {
  NPP npp;
  NPWindow window;
  NPObject *object;
}PluginInstance;

In my NPP_New method I have

 PluginInstance *newInstance = (PluginInstance*)malloc(sizeof(PluginInstance));
 bzero(newInstance, sizeof(PluginInstance));
 newInstance -> object = NPN_CreateObject(instance, &class);
 newInstance->npp = instance;
 instance->pdata = newInstance;

In my getValue method:

    NPObject* obj = ((PluginInstance *) (instance->pdata)) -> object;
    void **v = (void **)value;
    NPN_RetainObject(obj);
    *v = obj;

still the same problem

  • 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-06-09T03:04:42+00:00Added an answer on June 9, 2026 at 3:04 am

    You shouldn’t only fill out parts of the NPClass functions, most notably you are missing hasProperty & getProperty. Browsers may handle other missing functions, but as far as i know they are not required to.

    Also note that your NPP_GetValue() should only return the scriptable object for variable == NPPVpluginScriptableNPObject.
    You should then create scriptable objects per plugin instance (keep in mind that multiple instances of your plugin can run concurrently) and not forget to NPN_Release() the scriptable object when your plugin goes away.
    pinvoke() could be improved to:

    static bool pinvoke(NPObject* obj, NPIdentifier methodName, const NPVariant *args, 
                        uint32_t argCount, NPVariant *result)
    {
        if (!result) 
            return false;
        INT32_TO_NPVARIANT(32, *result);
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method getValue like this public Object getValue() { return Integer.valueOf(0); }
I have this line of code: this.Path = pathLookUpLocation.GetValue(RegLookupKey, null).ToString(); When I run static
I have this extension method for my BusinessObject class: public static class Extensions {
So i have this method: internal K GetValue<T, K>(T source, string col) where T
I have this method called MatchNodes: IEnumerable<bool> MatchNodes<T>(T n1, T n2) Which basically gets
I have this extension method: public static string GetValueFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>>
I have a protocol in Objective-C, something like this: @protocol Handler +(NSString*) getValue; @end
I use SmartGwt and I have the following line: formItem.getForm().getField(report_date).getValue().toString(); This returns something like
I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do
Say I have this class Myclass that contains this method: public class MyClass {

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.