我正在构建一个 dll,然后将其与 Firefox 扩展一起使用。
我设法在Windows下使用gcc构建了一个DLL:
#include<stdio.h>
int add(int a,int b)
{
return(a+b);
}
我现在尝试通过我的 dll 使用它。阅读了一些帖子,尤其是这篇文章后,我无法完成这项工作:将二进制组件引用到 js-ctypes
每次我尝试 ctypes.open 时,都会收到错误消息:无法加载库。但是,DLL 路径是正确的。这是JS代码:
Components.utils.import("resource://gre/modules/ctypes.jsm");
AddonManager.getAddonByID("[email protected]", 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);
文档
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)