NPAPI plug-in development record (three) -------npapi function return value (tur

Recommended for you: Get network issues from WhatsUp Gold. Not end users.


The npapi function returns the value of BOOL (String, Int returned to the browser, the function call Plugin)

Has long been accustomed to JS code calls the plugin function returns the value of bool call failed, two days before the project needs the function returns a string, the thought that something very simple, is to return a value, but do not want to go to war, to find for a long time can not find the reason, return bool,   int can, but the string will go wrong, finally through Google, finally found a solution. Method of converting first look at the NPAPI to provide:






Normally called directly conversion method, the return value is assigned to the returned pointer is good. Usually invoke (NPIdentifier  name,   const  NPVariant  *args,   uint32_t  argCount,   NPVariant  *result   result.) method.

For example,

Returns a Boolean value to determine the function of the success or failure of the call, BOOL  bReturn  =  m_ctrlWnd.SetCtrlParam (para);     BOOLEAN_TO_NPVARIANT (bReturn,   *result);   can be directly so call. The function succeeds, the JS terminal can receive true, otherwise it is false,

To return a number, can use



Calling method and booll.

Here only some difference is String,   when the need to return a string, NPNetscapeFuncs call interface browser provides a plug-in, allocate enough memory space to a string, and then convert.

extern NPNetscapeFuncs * browser;  //If the code is not defined, need to be defined in the np_entry  

const char * StringVariable = "";//As the function return value with the value. If it is Unicode, you must first convert the success of ANSI

char* outStr = (char*)browser->memalloc(strlen(StringVariable)+1);

if(!outStr) return false;

strcpy(outStr, StringVariable);

STRINGZ_TO_NPVARIANT(outStr, *result);

So that you can receive transfer string in page JS code value.

As for the obj method, return remains to be studied, welcome to clap brick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Donna at November 12, 2013 - 4:23 PM