NPAPI最简单的代码

具体代码编译参考下载的链接:

https://download.csdn.net/download/quantum7/11988429

 

注意,需要的接口版本必须是1.9.0.17:

#include 
#include 
#include 

#include "npupp.h"

NPNetscapeFuncs NPNFuncs;


char *
NP_GetMIMEDescription()
{
  return (char*)"application/mozill-plugin6:.foo5:Scriptability Plugin5";
}

NPError
NP_GetValue(void* future, NPPVariable variable, void *value)
{
  //return NPP_GetValue((NPP_t *)future, variable, value);

  NPP instance = (NPP_t *)future;

  if(instance == NULL)
    return NPERR_INVALID_INSTANCE_ERROR;

  switch (variable) {
  case NPPVpluginNameString:
    *((char **)value) = (char*)"NPRuntimeTest";
    break;

  case NPPVpluginDescriptionString:
    *((char **)value) = (char*)"NPRuntime scriptability API test plugin";
    break;

  case NPPVpluginScriptableNPObject:
    //*(NPObject **)value = plugin->GetScriptableObject();
    break;

  default:
    return NPERR_GENERIC_ERROR;
  }

  return NPERR_NO_ERROR;
}

编译办法:

XULRUNNER=xulrunner-sdk-190

rm *.so
rm *.o

g++ -shared -fPIC \
    np_entry.cpp \
    -I ${XULRUNNER}/include \
    -I ${XULRUNNER}/include/nspr \
    -I ${XULRUNNER}/include/plugin \
    -I ${XULRUNNER}/include/java \
    -I/usr/include/gtk-2.0 \
    -I/usr/include/glib-2.0 \
    -I/usr/include/pango-1.0 \
    -I/usr/lib64/glib-2.0/include \
    -I/usr/include/cairo \
    -I/usr/include/gdk-pixbuf-2.0 \
    -I/usr/include/atk-1.0 \
    -o libnprt.so \
   `pkg-config --libs --cflags gtk+-2.0`

 

你可能感兴趣的:(NPAPI插件)