Mozilla使用带有js-ctypes的C DLL

我想建立一个DLL,然后使用它与Firefox扩展。

我设法在Windows下使用gcc构建DLL:

#include int add(int a,int b) { return(a+b); } 

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

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

 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的路径部分不是您想要的 – 您需要文件路径:

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

文档