As CreateObject just takes Class variable as arguement, is it
possible to send some initilisation data so that on allocate it can be
used in next class.
Here is snippet -
in main plugin instace -
NPP_New
{
ObjectA = NPN_CreateObject(npp, getClassA)
}
in Object/Class A on invoke API_abc
API_abc(args)
{
ObjectB = NPN_CreateObject(npp, getClassB);
}
So If I have to initlise data at Object B from Object A at creation
what is best way ?
Regards
I'm not sure if anyone can say that there is a "Best way", but I can
tell you how I normally do it. I just have a static method on my
NPObject class called "NewObject"; I pass in my browser object (which
has the pointers to NPN_CreateObject and the NPP handle) as well as
any initialization parameters that I may need and it returns the
created and initialized object. This also makes it easy to keep track
of the NPClass, since it can just be a static protected member
variable of that class.
You can see an example here:
http://code.google.com/p/firebreath/source/browse/src/NpapiPlugin/NPJavascriptObject.h
http://code.google.com/p/firebreath/source/browse/src/NpapiPlugin/NPJavascriptObject.cpp
Good luck,
Richard
Cheers
Yes; the method I mentioned only works with objects that you
create. :-) NPN_Invoke and NPN_SetProperty will work on any
NPObject. I tend to be obsessively object oriented, but I'd probably
still create an object or method somewhere that takes the NPObject
params, creates the object, calls the appropriate initialization
(Invoke, SetProperty, whatever), and then returns it. For me, it's
nice to have it in one place. Since I can't have a real constructor,
using a construbor-type function to create the object seems like the
next best thing.
For what it's worth =]
Richard