現在のページの DOM にアクセスするための NPAPI プラグインを作成しています。私はプラグインを構築することができます。今、私は javascript 関数 console.debug("hello from c++"); を呼び出したいです。NPAPI プラグインから。次のコードを取得しました。Google の helloworld サンプル コードを使用して npapi プラグインをビルドしています。コード:
bool ScriptablePluginObject::Invoke(NPObject* obj, NPIdentifier methodName, const NPVariant* args,uint32_t argCount, NPVariant* result)
{
// The message i want to send.
char* message = "Hello from C++";
// Get window object.
NPObject* window = NULL;
NPN_GetValue(npp_, NPNVWindowNPObject, &window);
// Get console object.
NPVariant consoleVar;
NPIdentifier id = NPN_GetStringIdentifier("console");
NPN_GetProperty(npp_, window, id, &consoleVar);
NPObject* console = NPVARIANT_TO_OBJECT(consoleVar);
// Get the debug object.
id = NPN_GetStringIdentifier("debug");
// Invoke the call with the message!
NPVariant type;
STRINGZ_TO_NPVARIANT(message, type);
NPVariant args[] = { type };
NPVariant voidResponse;
NPN_Invoke(npp_, console, id, args,sizeof(args) / sizeof(args[0]),&voidResponse);
// Cleanup all allocated objects, otherwise, reference count and
// memory leaks will happen.
NPN_ReleaseObject(window);
NPN_ReleaseVariantValue(&consoleVar);
NPN_ReleaseVariantValue(&voidResponse);
}
しかし、test.htmlを呼び出しているときにロードした後、クラッシュしています。「このコードを正しい場所で呼び出していますか」と「このコードをテストするにはどうすればよいですか」を教えてください。
ありがとう...