Delphi调用C# 编写dll动态库

时间:2023-03-09 12:50:10
Delphi调用C# 编写dll动态库

Delphi调用C# 编写dll动态库

编写C#dll的方法都一样,首先在vs2005中创建一个“类库”项目WZPayDll,

using System.Runtime.InteropServices;
namespace WZPayDll
{
public interface IWZPay
{
void Pay(stirng url,string payType);
} [ClassInterface(ClassInterfaceType.None)]
public class WZPay:IWZPay
{
public void YourProcedure (stirng url,string payType);
{ //something is here,myself code
}
}
}

完成之后,选中该项目右击,选择属性,然后在应用程序中选择程序集信息如图:

Delphi调用C# 编写dll动态库

将图中红框的地方选中,然后

Delphi调用C# 编写dll动态库

然后在生成栏目中选中红框的为com互操作注册

接下来需要注册dll,

使用regasm.exe注册即可,为了方便注册,我们需要组一个批处理,要双击即可,

@echo off
start regasm2.0_x86.exe WZPayDll.dll
exit

  

见上述代码拷贝到文本文件中,然后保存为.bat的批出来,将regasm.exe文件和你的动态库,还有批处理放在同一个文件夹下,然后双击批出来接口注册完毕