현재 페이지의 DOM에 액세스 할 수있는 NPAPI 플러그인을 작성했습니다. 나는 플러그인을 만들 수있다. 지금 javascript 함수를 호출하려면 console.debug ("hello from C++"); NPAPI 플러그인에서 가져 왔습니다. 나는 코드 내가 NPAPI 플러그인을 구축하기 위해 구글에서 helloworld를 샘플 코드를 사용하고 다음 촬영 한 : 코드 :NPAPI 플러그인에서 javascript 함수 호출
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를 내가 부르고 로딩 후. "올바른 위치에서이 코드를 호출하고 있습니다"및 "이 코드를 테스트 할 수있는 방법"을 알려주십시오.
덕분에 ...