如何在 Iron python 中加载 DLL,用 c++ 编写并用 c# 包装

本文关键字:c++ 包装 DLL Iron python 加载 | 更新日期: 2023-09-27 18:31:13

我有一个最初用 c++ 编写的 dll,后来 C# 中的一个模块包装了它并使用了这个 导入:

[DllImport("myDLL.dll", CallingConvention=CallingConvention.Cdecl)]
    public static extern int init();

我现在正在使用Iron Python,并希望使用在此c#程序中导入的原始DLL中的函数。

基本上我不知道要导入什么到python中。 当我在 C# 中有一个简单的项目被转换为 DLL 时,我添加了它:

clr.AddReferenceToFileAndPath("my path")

然后我导入了命名空间和所有函数。

在这种情况下,我不明白我应该导入的女巫dll?任何帮助都将得到赞赏

编辑:

这就是我正在做的:

 >>> import sys
  >>> import clr
 >>> clr.AddReferenceToFileAndPath(r"wrapperPath.dll")
>>> import wrapper
>>> from wrapper import *
>>> init()
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'initialize' is not defined

如何在 Iron python 中加载 DLL,用 c++ 编写并用 c# 包装

C# 没有没有类的函数。 您的问题可能已通过 ParentClassName.init() 解决。 最好有一个实例方法调用 C++ P/Invoke 签名以进行调试或日志记录。 祝你好运。