To load C# dll into Delphi you need to do the following:
1. C# class as a COM
object, to achieve this put all your methods in one or more
interfaces then make the class implement each of those interfaces.
2. register the assembly as a COM object in the registry using regasm.
Sample code as shown below:
// IAddInterface.cs
public interface IAddInterface
{
int Add(int i1, int i2);
}
// SimpleDll.cs
using System.Runtime.InteropServices;
[ClassInterface(ClassInterfaceType.None)]
public class SimpleDLL : IAddInterface
{
public int Add(int i1, int i2)
{
return i1+i2;
}
}
csc /t:library /out:SimpleDll.dll *.cs
Next, register the assembly as a COM object in the registry using:
Code:
regasm SimpleDll.dll /tlb:Add.tlb
In Delphi, click Project->Import Type Library (like you did before). Select your .tlb (Add.tlb in this case) and click Create Unit.
main unit add "ComObj" and "SimpleDLL_TLB"
procedure TForm1.Button1Click(Sender: TObject);
var
intfRef: IAddInterface;
result: Integer;
begin
intfRef := CreateComObject(CLASS_SimpleDLL_) as IAddInterface;
result := intfRef.Add(2, 2);
Note: Delphi .exe needs to be in the same directory as the .NET DLL