title: How to pass c# string to delphi .dll PChar type?
body: <p>So I learned using IntPtr in this case,</p>
  
  <p>-delphi (delphi 2006 version) code</p>
  
  <pre><code> function GetRequestResult(out code:integer):PChar; stdcall;
     begin
      LogMessage('GetRequestResult');
      code:=requestCode;
      result:=PChar(RequestResult);
      LogMessage('GetRequestResult done');
     end;
  </code></pre>
  
  <p>then, for using in c#, 
  I used like, </p>
  
  <pre><code>IntPtr str = GetRequestResult(out code); 
  string loginResult = Marshal.PtrToStringAnsi(str); 
  </code></pre>
  
  <p>and this works well.</p>
  
  <p>Then, how about this case?</p>
  
  <p>-delphi code</p>
  
  <pre><code> procedure Login(login,password:PChar); stdcall;
  ...
  ...
  </code></pre>
  
  <p>this PChar is inside ().
  So what is exact way to pass string value to that Login delphi function?</p>
  
  <p>[DllImport ("ServerTool")]</p>
  
  <ol>
  <li><p>private static extern void Login([MarshalAs(UnmanagedType.LPStr)]string id, [MarshalAs(UnmanagedType.LPStr)]string pass);</p></li>
  <li><p>private static extern void Login(IntPtr id, IntPtr pass); 
  // in this case, how use this IntPtr in latter part?</p></li>
  <li><p>private static extern void Login(string id, string pass);</p></li>
  </ol>
  
  <p>Thanks in advance.</p>