如何在wxwebconnect中注册组件接口?

发布于 2024-09-30 09:54:03 字数 1624 浏览 0 评论 0原文

我正在使用 wxWebConnect 测试应用程序进行实验,并结合位于“http: //nerdlife.net/building-ac-xpcom-component-in-windows/"

我根据需要调整 MyComponent 类以与 testapp.exe 一起编译(而不是作为单独的 dll),并且在 MyApp::OnInit 上我有以下几行:

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);

这些行是从 GeckoEngine::Init() 复制的,使用相同的机制来注册 PromptService 等。代码编译良好,并且 testapp.exe 按预期运行。

我将 javascript 测试如下:

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;
}

并得到以下异常: 无法转换 JavaScript 参数 arg 0 [nsISupport.QueryInterface]

第一个警报显示“object”,因此该行

Components.classes[cid].createInstance()

返回创建的实例。

第二个警报显示“未定义”,因此 XULRunner 无法识别接口 nsIMyComponent。 如何在wxWebConnect环境中动态注册nsIMyComponent接口?

谢谢

I'm doing an experiment with wxWebConnect test application, incorporating the xpcom tutorial at "http://nerdlife.net/building-a-c-xpcom-component-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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

划一舟意中人 2024-10-07 09:54:03

我不确定这里发生了什么。我要检查的第一件事是您的组件是否可编写脚本(我认为是这样,因为您从中复制的演示是)。我要检查的下一件事是您是否可以实例化其他标准 XULRunner 组件并获取它们的接口(尝试类似“alert('Components.interfaces.nsIFile');”的内容 - 至少在我的 wxWebConnect 版本中这会显示一个警报框 。

另外,我认为值得检查错误控制台以确保没有报告错误或警告

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

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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文