开发者

problem of callback from C++ to JS

开发者 https://www.devze.com 2023-04-08 10:21 出处:网络
I\'m a newer to NPAPI. I come across one problem. in my plugin, I need to return some data from C++ to JavaScript, yes,that\'s callback. but the callback thread and the main thread are separate thread

I'm a newer to NPAPI. I come across one problem. in my plugin, I need to return some data from C++ to JavaScript, yes,that's callback. but the callback thread and the main thread are separate threads. So I use NPN_PluginThreadAsyncCall, but the problem can not be solved also. When callback, the firefox crashed... Can anyone help me?

the bellow codes are in the callback thread, Can anyone tell me, why it crashed?

npnfuncs->pluginthreadasynccall(instance,callBackfunc,(void*)pdata);
//////////////开发者_运维百科///////////////////////////////////////////////////////
void callBackfunc(void* arg)
{
    NPObject *winobj;
    npnfuncs->getvalue(instance,NPNVWindowNPObject,&winobj);

    NPVariant handler;
    NPIdentifier id1 = npnfuncs->getstringidentifier("MyTest".c_str());
    npnfuncs->getproperty(instance, winobj, id1, &handler);
    NPObject* handlerObj= NPVARIANT_TO_OBJECT(handler);

    NPVariant prototype;
    NPIdentifier id2 = npnfuncs->getstringidentifier("prototype");
    npnfuncs->getproperty(instance, serviceHandlerObj, id2, &prototype);
    NPObject* prototypeObj= NPVARIANT_TO_OBJECT(prototype);

    NPIdentifier id = npnfuncs->getstringidentifier("fun".c_str());

    NPVariant voidResponse;
    int status=npnfuncs->invoke(instance,prototypeObj,id,args,argCount,&voidResponse);
    return;
}    

thanks Best Regards greatsea


... What is "MyTest".c_str() supposed to be? This is C++, no? c_str() is a method of a std::string class, and I don't see that being sued here, so trying to do a .c_str() on it shouldn't even compile, unless there is something going on here that I really don't understand.

Also be aware that at least Safari 5.1 has stopped supporting NPN_PluginThreadAsyncCall and different methods need to be used to make cross-thread callbacks. I don't know if other browsers have or will or not; so far it doesn't seem so.

Is there a reason you're not just using FireBreath for your plugin? It solves all of these problems for you and lets you just focus on your plugin...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号