So I learned using IntPtr in this case,
-delphi (delphi 2006 version) code
function GetRequestResult(out code:integer):PChar; stdcall;
begin
LogMessage('GetRequestResult');
code:=requestCode;
result:=PChar(RequestResult);
LogMessage('GetRequestResult done');
end;
then, for using in c#, I used like,
IntPtr str = GetRequestResult(out code);
string loginResult = Marshal.PtrToStringAnsi(str);
and this works well.
Then, how about this case?
-delphi code
procedure Login(login,password:PChar); stdcall;
...
...
this PChar is inside (). So what is exact way to pass string value to that Login delphi function?
[DllImport ("ServerTool")]
private static extern void Login([MarshalAs(UnmanagedType.LPStr)]string id, [MarshalAs(UnmanagedType.LPStr)]string pass);
private static extern void Login(IntPtr id, IntPtr pass); // in this case, how use this IntPtr in latter part?
private static extern void Login(string id, string pass);
Thanks in advance.
PAnsiChar
(which is always equivalent tochar *
type in C, regardless of Delphi version) on stackoverflow, if the underlying DLL is delphi 7 dll, or XE then the signature you've listed above would have two different meanings. – Warren P