在C / C ++ DLL中导出MSVS 2013中的函数以供Mozilla js-ctypes使用

用户名

我正在尝试通过FireFox的js-ctypes从MSVS 2013 C / C ++ DLL访问一些导出的函数。我试过了 :

这是我的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文件...

知道为什么什么都没发现吗?

相关问题:

使Visual Studio中的C DLL适合Mozilla中的js-ctypes使用

构建一个供Mozilla js-ctypes使用的DLL

用户名

好的。这是我用过的:

  • 32位平台的构建设置(来自配置管理器)。
  • 调用约定:__cdecl(/ Gd)
  • 编译为:作为C ++代码(/ TP)编译
  • 不使用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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使Visual Studio中的C DLL适合Mozilla中的js-ctypes使用

从dll中导出C ++函数而无需外部“ C”

使用 ctypes 的 .dll 中的 python 中的 C++ 函数 - 找不到函数和访问冲突

如何导出C#dll方法/函数以在C ++中使用它

使用ctypes将C ++函数导出到python:未定义符号

如何使用ctypes将python列表传递给C函数(dll)

使用Python ctypes运行C dll函数时遇到问题(大小未知的数组输出)

将python列表传递给使用ctypes返回数组数据的“c”DLL函数

使用CMake时如何在Emscripten中导出C函数

使用ctypes将C数组从C函数返回到Python

在 Python 中使用 Ctypes 读取 Dll 的双 c 结构

使用 ctypes 将字节 numpy 数组传递给 C 函数

使用ctypes通过指针args调用C ++函数

使用python ctypes通过引用c ++函数传递长向量

如何使用ctypes将numpy ndarrays传递给C ++函数?

C#导出函数dll

使用ctypes在Python中解码C const char *

使用结构类型参数调用c ++ dll的导出函数的powershell

使用ctypes包装DLL函数

使用 ctypes 访问 DLL 函数

使用_stdcall将更改dll中导出函数的名称

如何使用js-ctypes Firefox扩展调用本地C代码?

在Windows上使用ctypes在python中包装c ++函数:未找到函数

通过使用ctypes调用C函数从C函数返回的意外整数

是否可以在DLL中导出具有C链接的C ++成员方法?

C ++-使用ctypes进行Python绑定-在函数中返回多个值

在不使用C函数的情况下更新ctypes python中的结构指针的值

如何使用ctypes从Python创建C结构?

是否可以通过Ctypes使用指向3dim数组的指针来调用C DLL?