In Delphi I have a structure like this:
TCustomerInfo = Packed Record
CustomerNo: Integer;
FirstName: String[50];
LastName: String[50];
End;
With a dummy-proc like this:
procedure GetCustomer(CustomerNo: Integer; var CustomerInfo: TCustomerInfo);
begin
CustomerInfo.CustomerNo := 19901;
CustomerInfo.FirstName := 'JOHN';
CustomerInfo.LastName := 'DOE';
end;
In C# I have this:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
struct CUSTOMER_INFO
{
public Int32 CustomerNo;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=50)]
public string FirstName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=50)]
public string LastName;
}
With an imported Delphi function like this:
[DllImport("Exceline.dll")]
extern static void GetCustomer(Int32 CustomerNo, ref CUSTOMER_INFO CustomerInfo);
The idea is to make sure all memory allocation and storage is being handled by the C# application.
My problem is that nothing gets assigned to my C# struct upon return from GetCustomer :-/