I need to create a DLL in Delphi 7 and consume it in C #, when the parameters and return are int there are no problems, the problem occurs when I try to use string in return, I put in Delphi a MessageDlg and I saw that the input parameter is going correctly, BreakPoint does not generate exception, simply the test console application dies when I make the call.
Delphi
function Mensagem(texto: string): PAnsiChar; stdcall;
var
msg: str
begin
msg := texto;
Result := PAnsiChar(msg);
end;
exports
Mensagem;
C #
[DllImport(@"teste.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
static extern string Mensagem([MarshalAs(UnmanagedType.AnsiBStr)]string msg);