I want to call a third-party NPAPI DLL file in C, but I made a mistake in creating an instance.
#include <Windows.h>
#include <stdio.h>
#include "npapi.h"
#include "npfunctions.h"
#include "npruntime.h"
#include "nptypes.h"
short address;
typedef NPError (*pGetProcAddress)(NPPluginFuncs*);
NP_GetEntryPointsFunc _GetEntryPointsFunc;
NP_InitializeFunc _InitializeFunc;
NPPluginFuncs* pFuncs;
NPNetscapeFuncs* sBrowserFuncs;
NPObject* np_object;
NPClass *np_class;
NPP_t npp;
char szMimeType[] = "application/x-np-piao";
int main(){
npp.pdata = 0;
npp.ndata = &npp;
pFuncs = (NPPluginFuncs*)malloc(sizeof(NPPluginFuncs));
sBrowserFuncs = (NPNetscapeFuncs*)malloc(sizeof(NPNetscapeFuncs));
HMODULE hDLL = LoadLibrary("helper.dll");
if(hDLL != NULL){
printf("load library success\n");
}
_GetEntryPointsFunc = (NP_GetEntryPointsFunc)GetProcAddress(hDLL,"NP_GetEntryPoints");
if (_GetEntryPointsFunc)
{
int status = _GetEntryPointsFunc(pFuncs);
printf("NP_GetEntryPointsFunc status %d\n",status);
printf("version %d\n",pFuncs->version);
}
_InitializeFunc = (NP_InitializeFunc)GetProcAddress(hDLL, "NP_Initialize");
if (_InitializeFunc)
{
int status = _InitializeFunc(sBrowserFuncs);
printf("NP_InitializeFunc status %d\n",status);
}
int status = pFuncs->newp(szMimeType, &npp, NP_EMBED, 0, 0, 0, NULL);
printf("newp status %d\n",status);
printf("version %d\n",pFuncs->version);
/**********************************************/
status = pFuncs->getvalue(&npp,NPPVpluginScriptableNPObject,&np_object);//have problem!!!
printf("getvalue status %d\n",status);
/*********************************************/
}
Here is the result of the operation. output pic
In the call to [NP_GetEntryPoints] and [NP_Initialize], all returned to normal, until [pFuncs->getvalue].
As you can see, “getvalue status ” also not appear in output.I want to know what causes this problem and whether there is a better way to solve it.
Forgive my poor English and thank you for your help.
It's hard to say what might be causing your problem, but offhand I'd say one definite red flag is that you haven't filled out the function pointers in sBrowserFuncs -- these aren't provided by the plugin, they are provided by the browser. That's almost certainly your first problem.