четвер, 3 грудня 2009 р.

How to call NPN functions in NPAPI plugin

For every NPN function used like NPN_GetValue, NPN_Evaluate, NPN_ReleaseVariantValue etc. one has to write a wrapper. First of all we need to save pointer to NPNetscapeFuncs* which is passed to NP_Initalize:

NPNetscapeFuncs* npnfuncs;
NPError NP_Initialize(NPNetscapeFuncs *npnf) {
npnfuncs = npnf;
}

Then we need to write a wrapper for each function. Here goes an example for NPN_GetValue, NPN_Evaluate, NPN_ReleaseVariantValue:
/* Wrappers for NPN functions */

NPError NP_LOADDS NPN_GetValue(NPP instance, NPNVariable variable, void *value)
{
return npnfuncs->getvalue(instance, variable, value);
}

bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script,
NPVariant *result)
{
return npnfuncs->evaluate(npp, npobj, script, result);
}

void NPN_ReleaseVariantValue(NPVariant *variant)
{
npnfuncs->releasevariantvalue(variant);
}

Немає коментарів: