我正在尝试通过FireFox的js-ctypes从MSVS 2013 C / C ++ DLL访问一些导出的函数。我试过了 :
default_abi
,stdcall_abi
,winapi_abi
)这是我的DLL代码:
#define DllExport extern "C" __declspec(dllexport)
DllExport void Test()
{
::MessageBox(NULL, _T("Test!"), _T("Title"), MB_OK);
}
无论我尝试什么,似乎总是会收到此错误:
console.error: myxpi:
Message: Error: couldn't find function symbol in library
Stack:
openScratchpad@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///c:/users/kgk/appdata/local/temp/tmpdyrqfd.mozrunner/
extensions/[email protected]!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid1-qeiy1nt1uinqug-at-jetpack/myxpi/lib/main.js:34:18
button<.onClick@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///c:/users/kgk/appdata/local/temp/tmpdyrqfd.mozrunner/extensions/[email protected]!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid1-qeiy1nt1uinqug-at-jetpack/myxpi/lib/main.js:16:9
有人知道什么是正确的设置吗?
FF是32位(据我所知),但我不知道它是否使用python之类的东西来加载DLL。
我认为,只要导出函数使用正确的声明(例如__cdecl
),“编译为”就无关紧要。
我不确定会产生什么(但我的项目设置适用于__cdecl
):
#define DllExport extern "C" __declspec(dllexport)
但是我也尝试过替换它并使用DEF文件...
知道为什么什么都没发现吗?
相关问题:
好的。这是我用过的:
这段代码:
#define DllExport extern "C" __declspec(dllexport)
DllExport void Test()
{
::MessageBox(NULL, _T("Test!"), _T("Title"), MB_OK);
}
JS:
var lib = ctypes.open("C:\\Users\\user\\Desktop\\myXPI\\lib\\MyAddonCore.dll");
var test = lib.declare("Test", ctypes.winapi_abi, ctypes.void_t);
test();
lib.close();
您必须为不带void
参数的函数定义一个参数(用于Kinjal Dixit
下面指出的返回值)!
不幸的是,这没有找到DLL路径(我想知道为什么...:|):
var lib = ctypes.open(self.data.url('MyAddonCore.dll'));
干杯!
更新:
这是获取DLL路径的一些代码:
http://www.acnenomor.com/3342758p1/how-to-load-dll-from-sdk-addon-data-folder
const {Cc, Cu, Ci} = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");
const ResProtocolHandler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
const ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
function resolveToFile(uri) {
switch (uri.scheme) {
case "chrome":
return resolveToFile(ChromeRegistry.convertChromeURL(uri));
case "resource":
return resolveToFile(Services.io.newURI(ResProtocolHandler.resolveURI(uri), null, null));
case "file":
return uri.QueryInterface(Ci.nsIFileURL).file;
default:
throw new Error("Cannot resolve");
}
}
var self = require("sdk/self");
let dll = self.data.url("test.dll");
dll = resolveToFile(Services.io.newURI(dll, null, null));
console.log(dll.path); // dll.path is the full, platform-dependent path for the file.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句