Delphi (UnicodeString):
function ShowDelphiMsg(inputStr : UnicodeString) : UnicodeString; stdcall; var a : UnicodeString; begin ShowMessage(inputStr); a := 'Тест!'; result := a; end; C #
[DllImport("Native.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] [return: MarshalAs(UnmanagedType.LPWStr)] internal static extern string ShowDelphiMsg([MarshalAs(UnmanagedType.LPWStr)] string inputStr); This option perfectly transmits a string from C # to Delphi, Delphi prints the string. But the main problem is an error when returning a string from Delphi.
Vporos: Which UnmanagedType matches a UnicodeString from Delphi?
ps architecture for both x64 applications.
Delphi (WideString):
function ShowDelphiMsg(inputStr : WideString) : WideString; stdcall; var a : WideString; begin ShowMessage(inputStr); a := 'Тест!'; result := a; end; It also causes an error when returning a value.
Simplified function
C #:
[DllImport("Native.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] [return: MarshalAs(UnmanagedType.BStr)] internal static extern string ShowDelphiMsg(); Delphi:
function ShowDelphiMsg() : WideString; stdcall; var a : WideString; begin a := 'Тест!'; result := a; end; The same mistake.
string ShowDelphiMsg();- Does it overlap the previousUnmanagedType.BStr? - kami