Mozilla使用带有js-ctypes的C DLL [英] Mozilla use a C DLL with js-ctypes

查看:167
本文介绍了Mozilla使用带有js-ctypes的C DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个DLL,然后使用Firefox扩展。

I'm tying to build a dll, and then use it with a Firefox extension.

我设法使用Windows下的gcc构建一个DLL:

I managed to build a DLL using gcc under Windows :

#include<stdio.h>
int add(int a,int b)
{
    return(a+b);
}

我现在尝试通过我的dll使用它。在阅读了一些帖子后,尤其是这篇文章,我无法设法使这项工作:将二进制组件引用到js-ctypes

I try now to use it through my dll. After reading some posts, especially this one, I couldn't manage to make this work: Reference a binary-component to js-ctypes

每次尝试ctypes.open时,我都有错误消息:无法加载库。但是,DLL路径是正确的。这是JS代码:

Each time I try ctypes.open, I have the error message: couldn't load the library. However, the DLL path is correct. Here is the JS code:

Components.utils.import("resource://gre/modules/ctypes.jsm");

AddonManager.getAddonByID("greenfox@octo.com", function(addon)
{
    var libcPath = addon.getResourceURI("components/library.dll");

    if (libcPath instanceof Components.interfaces.nsIURI)
    {
        var libc = ctypes.open(libcPath.path);

        var libc = ctypes.open(libc);

        /* import a function */
        var puts = libc.declare("add", /* function name */
                   ctypes.default_abi, /* call ABI */
                   ctypes.int32_t, /* return type */
                   ctypes.int32_t, /* argument type */
                   ctypes.int32_t /* argument type */
          );

          var ret = puts(1,2);

          alert("1+2="+ret);

    }

你有什么想法吗?

推荐答案

URI的路径部分不是你想要的 - 你想要的文件路径:

The path part of the URI is not what you want to have here - you want the file path:

if (libcPath instanceof Components.interfaces.nsIFileURL)
{
    var libc = ctypes.open(libcPath.file.path);

文档

这篇关于Mozilla使用带有js-ctypes的C DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆