我用单一方法编写了.Net 3.5 dll,供Delphi .exe调用。 不幸的是,它不起作用。
步骤: 1. 使用代码创建 C# 3.5 dll:
public class MyDllClass
{
public static int MyDllMethod(int i)
{
MessageBox.Show("The number is " + i.ToString());
}
}
- 转到 Assembly Properties --> Assembly Information 并选中“Make Assembly COM-Visible”
- 使用 RegAsm.exe 注册我的 dll
这会抛出 Delphi 异常,表明它无法连接 dll。 从非托管代码启用 C# 托管 dll 的使用需要哪些步骤。
有没有人熟悉关于这个主题的好例子?
谢谢
最佳答案
使用我的 project template for unmanaged exports 跳过 COM 部分可能会更幸运
class MyDllClass
{
[DllExport]
static int MyDllMethod(int i)
{
MessageBox.Show("The number is " + i.ToString());
return i + 2;
}
}
在 Delphi 中,您可以像这样导入它:
function MyDllMethod(i : Integer) : Integer; stdcall; extern 'YourAssembly.dll';
不过,我不得不否决你的问题。甚至不关心提供可以编译的代码。 (您的 C# 方法不返回值,但它期望为 int)
关于c# - 从 Delphi 调用 C# dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6174584/