Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't pass a C++ object to javascript; what you can do is pass an NPObject that is also a C++ object and exposes things through the NPRuntime interface.</p> <p>See <a href="http://npapi.com/tutorial3" rel="nofollow">http://npapi.com/tutorial3</a> for more information.</p> <p>You may also want to look at the <a href="http://www.firebreath.org" rel="nofollow">FireBreath</a> framework, which greatly simplifies things like this.</p> <p><strong>Edit</strong>: it seems I misunderstood your question. What you want is to be able to store data linked to a plugin instance. What you need is the NPP that is given to you when your plugin is created; the NPP has two members, ndata (netscape data) and pdata (plugin data). The pdata pointer is yours to control -- you can set it to point to any arbitrary value that you want, and then cast it back to the real type whenever you want to use it. Be sure to cast it back and delete it on NPP_Destroy, of course. I usually create a struct to keep a few pieces of information in it. FireBreath uses this and sends all plugin calls into a Plugin object instance so that you can act as though it were a normal object.</p> <p>Relevant code example from FireBreath: <a href="https://github.com/firebreath/FireBreath/blob/master/src/NpapiCore/NpapiPluginModule_NPP.cpp#L145" rel="nofollow">https://github.com/firebreath/FireBreath/blob/master/src/NpapiCore/NpapiPluginModule_NPP.cpp#L145</a> </p> <p>Pay particular attention to NPP_New and NPP_Destroy; also pay particular attention to how the pdata member of the NPP is used.</p> <p>This is also discussed in <a href="http://npapi.com/tutorial2" rel="nofollow">http://npapi.com/tutorial2</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COI'm not trying to pass a C++ object to JavaScript; I'm trying to pass a pointer to a C++ object to my plugin, so that it's accessible within the NPAPI interface on the C++ side (for example, I would like to access it in NPP_SetWindow and related functions, if possible). It seems strange to me that there's no (obvious?) way to pass private data to my NPAPI plugin.
      singulars
    2. COSorry I misunderstood; I have revised my answer to hopefully better answer your question. A suggestion, if I may: don't vote things down until you give people a chance to revise their answer if they just misunderstood you. You may annoy them enough that they won't bother answering. Also, if you had followed the tutorial link and looked around, you would have found the answer to my question on tutorial2; granted that's a lot of reading. I still would recommend looking at FireBreath rather than doing this by hand.
      singulars
    3. COIn the example you posted (NpapiPluginModule_NPP.cpp), NpapiDataHolder is instantiated in NPP_New and associated with pdata. That much I understood, but my issue is that I want to associate an object with pdata that was created _before_ the plugin instance was instantiated. In other words, I was hoping there was some mechanism available that would allow me to pass my own data pointer to NPP_New. I'm starting to think that the only way for me to go about this would be to use SetWindowLongPtr to associate my data pointer with a window handle; I could then fetch that pointer in NPP_SetWindow.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload