4
I need to create a dll in C# so I can use it in Delphi.
I tried the following:
I created a basic dll with a sum method, but when calling it in Delphi does not return anything, it would be like the created method does 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 as I try to call it at 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 also used an application called DDL Export Viewer that shows the methods of dll, but for mine shows nothing, and trying to validate the State Registration provided by sintegra presents the method of the same.
A . Net DLL is not standard, so you won’t get it this way. There must be a way to do this, I have some ideas, but I’m not going to risk having no experience and solid knowledge with it.
– Maniero
Ariel, I have a question with basically the same title http://answall.com/q/8107/5846
– Pablo Tondolo de Vargas
The solution is to declare the classes in C# as Comvisible and consume in Delphi as Activex instead of DLL Windows. Delphi is very good at importing Activex objects, generating Wrappers for them and managing the life cycle, very cool. I worked on many projects like this. Unfortunately I don’t have access now to any code that can yield an answer, but go down this path that you won’t regret: Comvisible in C# and consumption as Activex in Delphi. There must be examples on the net. Good luck!
– Caffé
http://answall.com/questions/47254/com-interop-com-client-e-server/47328#47328
– rubStackOverflow