天天看點

JS向NPAPI傳遞參數,并傳回結果

這個隻說簡單的參數。

static bool js_call_function(const NPObject* npobj, const NPVariand* args, const unint32_t argCount, NPVariant* result)
{
...
//取值
//NPVARIANT_TO_BOOLEAN(args[0]);
//NPVARIANT_TO_INT32(  args[0]);
//NPVARIANT_TO_DOUBLE( args[0]);
 
NPString str = NPVARIANT_TO_STRING(args[0]);
char* ca = (char*)malloc(str.UTF8Length+1);
memset(ca, 0, str.UTF8Length+1);
strncpy(ca, str.UTF8Characters, str.UTF8Length);
 
...
 
//BOOLEAN_TO_NPVARIANT(result);
//  INT32_TO_NPVARIANT(result);
// DOUBLE_TO_NPVARIANT(result);
 
//傳回值
char* text = "quantum7";
STRINGN_TO_NPVARIANT(text, strlen(text), *result);
 
}      

對于NPVARIANT_TO_OBJECT()/OBJECT_TO_NPVARIANT(),參考:

https://blog.csdn.net/quantum7/article/details/99705484

繼續閱讀