在MSVS 2013中导出功能用于C / C ++ DLL,以供Mozilla js-ctypes使用 [英] Exporting functions in MSVS 2013 in C/C++ DLL for Mozilla js-ctypes to use
问题描述
我试图通过FireFox的js-ctypes从MSVS 2013 C / C ++ DLL访问一些导出的函数。
我尝试过:
I am trying to access some exported functions from a MSVS 2013 C/C++ DLL via FireFox's js-ctypes. I have tried :
- 将编译为设置更改为C和C ++
- 更改平台的位数(32比64位)。
- 从这里使用ALL所有可用的ABI常量: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/ctypes (
default_abi
,stdcall_abi
,winapi_abi
) - 我已经使用Dependency Walker检查了我的DLL,并确保其名称没有装饰,我的功能确实导出了。
- Changing the "Compile As" settings to C and C++
- Changing the platform bitness (32 vs 64 bits).
- Using ALL the available ABI constants from here: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/ctypes (
default_abi
,stdcall_abi
,winapi_abi
) - I have checked my DLL using "Dependency Walker" and made sure that its name was not decorated and that my function was indeed exported.
这是我的DLL代码:
#define DllExport extern "C" __declspec(dllexport)
DllExport void Test()
{
::MessageBox(NULL, _T("Test!"), _T("Title"), MB_OK);
}
无论我尝试什么,似乎总是得到这个错误: / p>
No matter what I try, it seems that I always get this error:
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/jid1-QEiY1nT1Uinqug@jetpack.xpi!/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/jid1-QEiY1nT1Uinqug@jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid1-qeiy1nt1uinqug-at-jetpack/myxpi/lib/main.js:16:9
<有没有人知道什么是正确的设置?
Does anyone have any idea what are the proper settings?
FF是32位(据我所知),但我不知道是否使用其他的东西像python加载DLL。
FF is 32 bits (as far as I know) but I don't know if it uses something else like python to load the DLL.
我认为只要导出函数使用正确的声明(例如<$ c $),Compile As就不重要c#_c cdecl )。
I thought that the "Compile As" wouldn't matter as long as the exporting functions used the proper declaration (e.g. __cdecl
).
我不知道这是怎么产生的(但我的项目设置是 __ cdecl
):
I am not sure what this produces though (but my project settings are for __cdecl
):
#define DllExport extern "C" __declspec(dllexport)
但是我已经尝试使用DEF文件替换了...
But I have tried replacing that too and using DEF files...
任何想法,为什么没有什么似乎炒作?
Any idea why nothing seems to wok?
相关问题:
在Visual Studio su中创建一个C DLL可以在Mozilla中使用js-ctypes
推荐答案
行。这是我使用的:
- 为32位平台(从配置管理器)构建设置。
- 编译为:编译为C ++代码(/ TP)
- 不使用DEF文件 - >输入 - >模块定义文件)
-
此代码:
编译惯例:__cdecl(/ Gd)
- Build settings for 32bit platform (from config. manager).
- Calling convention: __cdecl (/Gd)
- Compile As: Compile as C++ Code (/TP)
- Using no DEF files (Linker->Input->Module Definition File)
This code:
#define DllExport extern "C" __declspec(dllexport)
DllExport void Test()
{
::MessageBox(NULL, _T("Test!"), _T("Title"), MB_OK);
}
JS: p>
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
在下面指出)!
You have to define a void
argument for functions with no arguments (it's for the return value as Kinjal Dixit
pointed out below)!
不幸的是,找到DLL路径(我想知道为什么...:|):
Unfortunately this didn't find the DLL path (I wonder why... :| ):
var lib = ctypes.open(self.data.url('MyAddonCore.dll'));
干杯!
更新:
这里有一些代码来获取DLL路径:
And here is some code to get the DLL path :
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.
这篇关于在MSVS 2013中导出功能用于C / C ++ DLL,以供Mozilla js-ctypes使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!