Mozilla的使用与JS-ctypes的一个C DLL [英] Mozilla use a C DLL with js-ctypes
问题描述
我绑建立一个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来使用它。阅读一些职位,特别是这一次之后,我无法管理,使这项工作:<一href=\"http://stackoverflow.com/questions/6175608/reference-a-binary-component-to-js-ctypes-firefox-addon/6257595#6257595\">Reference二进制组件JS-ctypes的 - Firefox的插件
每一次我尝试ctypes.open,我有错误消息:无法加载库。但是,DLL路径是正确的。这里是JS code:
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屋!