I need to create a C # dll so I can use it in delphi.
I've tried the following:
I created a basic dll with a sum method, but calling it in delphi does not return anything, it would be like the created method did not exist.
Below the code in C #:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace ClasseCom
{
[ClassInterface(ClassInterfaceType.None)]
public class soma
{
public soma() { }
public double somar(int a, int b)
{
return a + b;
}
}
}
Here's how I try to call it in Delphi 7:
procedure TForm1.Button1Click(Sender: TObject);
var
Handle : THandle;
somar : TSomaDll;
total : Double;
begin
Handle:=LoadLibrary ('ClasseCom.dll');
if Handle <> 0 then begin
@somar:=GetProcAddress(Handle, 'somar');
if @somar <> nil then
total := somar(1, 2);
FreeLibrary (Handle);
end;
ShowMessage(FloatToStr(total));
end;
In Delphi the variable @soma
is returning as nil
.
I've also used an application called DDL Export Viewer which shows the methods of the dll, but for my does not present anything, and trying the validation of the State Registration provided by the syntegra presents the same method.