Using C# DLL in Lazarus lazarus / 67-Windows ---------------------------------------------------------------------- JohnRambo · 2017-09-20 18:16 At first I admit that in C # I am green like chives. I want to prepare a C# DLL using the UnmanagedExports tool (https://www.nuget.org/packages/UnmanagedExports) in the C # DLL. Here's an example by author:https://stackoverflow.com/a/2055508/1919267 . So far ok, managed to produce a DLL and use it in Delphi. But there is a problem: when I want to use the same file in Lazarus, it returns nothing. The code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  adder : IDotNetAdder;begin  try   CreateDotNetAdder(adder);   Writeln('4 + 3 = ', adder.Add3(4));  returns me 0 (so I am thinking that DLL response  is nil). Is there any solution to fix that? Should I need to fix my pascal code or fix that DLL? ---------------------------------------------------------------------- avra · 2017-09-21 09:11 Next time you cross post I will hold my comments...  Please do not cross post in the future. ---------------------------------------------------------------------- tudi_x · 2017-09-21 09:30 @avra - the deletion of posts does not seem to work. maybe he opened a new one due to code not inserted as recommended in the first place. @rambo - i think you need to have a handler for the dll and define the external function, something like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TGetDeviceInfo = function(AIndex: integer): PTDeviceInfoRecord; cdecl; after you define the handler and the function you can use it. ---------------------------------------------------------------------- JohnRambo · 2017-09-21 13:30 Sorry for double topic but I can't delete topic in wrong category. I cant use COM, because I need to use old version of Lazarus (without ActiveX). In my code I declare procedure in static way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  Form1: TForm1;  procedure createdotnetadder(out instance:IDotNetAdder); stdcall external 'DelphiNETstd.dll' name 'createdotnetadder';implementation{ TForm1 }When I try to do it dynammicaly nothing work, only more problems. I don't understand that Delphi do it perfectly, but Lazarus not. In attachments I put .dll file and my pas unit. I don't asking about do it for me but to show me the way ---------------------------------------------------------------------- JohnRambo · 2017-09-21 14:53 OK I made it. Firstly we need to get some information: https://stackoverflow.com/a/9353800 "In C#/C++ you will need to define the Result as out Parameter, in order to maintain binary code compatibility of stdcall calling conventions" - thats the key. In my C# code I was use return. For Delphi its ok, but for Lazarus it is problematic. So I retyped my c# code from: Code: C#  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    [ComVisible(true)]    [ClassInterface(ClassInterfaceType.None)]    public class DotNetAdder : DelphiNET.IDotNetAdder    {        public void Add3(int left)        {            return= left + 3;                  }    } to Code: C#  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    [ComVisible(true)]    [ClassInterface(ClassInterfaceType.None)]    public class DotNetAdder : DelphiNET.IDotNetAdder    {        public void Add3(int left,out int result)        {            result= left + 3;                    }    }And change my pascal code from: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //interface:  type  IDotNetAdder = interface  ['{ACEEED92-1A35-43fd-8FD8-9BA0F2D7AC31}']    function Add3(left : integer):integer; stdcall;  end; //execution:var  adder : IDotNetAdder;begin  try   CreateDotNetAdder(adder);   Writeln('4 + 3 = ', adder.Add3(4)); to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  //interface:  type  IDotNetAdder = interface  ['{ACEEED92-1A35-43fd-8FD8-9BA0F2D7AC31}']    function Add3(left : integer;out result:integer); stdcall;  end;  //execution: CreateDotNetAdder(adder);   i:=4;   finally   adder.Add3(i,x);  showmessage('4 + 3 = '+ (inttostr(x))); ---------------------------------------------------------------------- Cyrax · 2017-09-21 15:01 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i void Add3(int left) translates to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Add3(left:integer) If you want result from your subroutine, you need to change C# code to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i int Add3(int left) and Pascal version to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function Add3(left:integer) : integer