Since Delphi 2005, one can use the Library item in the Item Categories: "Delphi for .NET Projects", in the New Items dialog, to allow Delphi Win32 applications to access any Delphi for .NET routine.

All exported .NET routines are seen as stdcall routines on the Win32 side.

For example, to marshal strings between Delphi for .NET and Delphi Win32, here's a few ways:

library MyNETLibrary; // Delphi for .NET Library

{$UNSAFECODE ON}
uses
  System.Runtime.InteropServices;

procedure Hello1([MarshalAs(UnmanagedType.LPWStr)]S: String);
begin
  System.Console.WriteLine('Hello, ' + S);
end;

procedure Hello2([MarshalAs(UnmanagedType.LPStr)]S: string);
begin
  System.Console.WriteLine('Hello, ' + S);
end;

function SomeWideStringFunc1: string;
begin
  Result := 'This is some string 1';
end;

[result: MarshalAs(UnmanagedType.LPStr)]
function SomeWideStringFunc2: string;
begin
  Result := 'This is some string 2';
end;

exports SomeWideStringFunc1, SomeWideStringFunc2,  Hello1, Hello2;

 


// Delphi for Win32 declarations


function SomeWideStringFunc1: PWideChar; external MyLib name 'SomeWideStringFunc1';
function SomeWideStringFunc2: PChar; external MyLib name 'SomeWideStringFunc2';
procedure Hello1(S: PWideChar); stdcall; external MyLib name 'Hello1';
procedure Hello2(S: string); stdcall; external MyLib name 'Hello2';


I think that's enough for this time round...