开发者

How to register component interface in wxwebconnect?

I'm doing an experiment with wxWebConnect test application, incorporating the xpcom tutorial at "http://nerdlife.net/building-a-c-xpcom-c开发者_JAVA百科omponent-in-windows/"

I adapt MyComponent class as necessary to compile together with testapp.exe (not as separate dll), and on MyApp::OnInit I have the following lines:

ns_smartptr<nsIComponentRegistrar> comp_reg;
res = NS_GetComponentRegistrar(&comp_reg.p);
if (NS_FAILED(res))
    return false;

ns_smartptr<nsIFactory> prompt_factory;
CreateMyComponentFactory(&prompt_factory.p);

nsCID prompt_cid = MYCOMPONENT_CID;
res = comp_reg->RegisterFactory(prompt_cid,
                                "MyComponent",
                                "@mozilla.org/mycomp;1",
                                prompt_factory);

Those lines are copied from GeckoEngine::Init(), using the same mechanism to register PromptService, etc. The code compiles well and testapp.exe is running as expected.

I put javascript test as below :

try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    const cid = "@mozilla.org/mycomp;1";
    obj = Components.classes[cid].createInstance();
    alert(typeof obj);
    // bind the instance we just created to our interface
    alert(Components.interfaces.nsIMyComponent);
    obj = obj.QueryInterface(Components.interfaces.nsIMyComponent);
} catch (err) {
    alert(err);
    return;
}

and get the following exception: Could not convert JavaScript argument arg 0 [nsISupport.QueryInterface]

The first alert says "object", so the line

Components.classes[cid].createInstance()

is returning the created instance.

The second alert says "undefined", so the interface nsIMyComponent is not recognized by XULRunner. How to dynamically registering nsIMyComponent interface in wxWebConnect environment ?

Thx


I'm not sure what is happening here. The first thing I would check is that your component is scriptable (I assume it is, since the demo you copy from is). The next thing I would check is whether you can instantiate other, standard XULRunner components and get their interface (try something like "alert('Components.interfaces.nsIFile');" - at least in my version of wxWebConnect this shows an alert box with string "nsIFile".

Also, I think it would be worth checking the Error Console to make sure there are no errors or warnings reported. A magic string to do that (in Javascript) is:

window.open('chrome://global/content/console.xul', '', 'chrome,dialog=no,toolbar,resizable');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜