title: How to use Delphi Dll(with PChar type) in C#
body: <p>Here is the Delphi DLL code:</p>
  
  <pre><code>library Project2;
  
  uses
    SysUtils,
    Classes;
  
  {$R *.res}
  
  function SimpleConv(const s: string): string;
  var
    i: Integer;
  begin
    Result := '';
    for i := 1 to Length(s) do
      if Ord(S[i]) &lt; 91 then
        Result := Result + S[i];
  end;
  
  function MsgEncode(pIn: pchar; InLen: Integer; var pOut: pchar; var OutLen: Integer): Boolean; stdcall;
  var
    sIn: string;
    sOut: string;
  begin
    SetLength(sIn, InLen);
    Move(pIn^, sIn[1], InLen);
  
    sOut := SimpleConv(sIn);   // Do something
  
    OutLen := Length(sOut);
    GetMem(pOut, OutLen);
    Move(sOut[1], pOut^, OutLen);
    Result := OutLen &gt; 0;
  end;
  
  procedure BlockFree(Buf: pchar); stdcall;
  begin
    if assigned(Buf) then
       FreeMem(Buf);
  end;
  
  exports
    MsgEncode,
    BlockFree;
  
  begin
  end.
  </code></pre>
  
  <p>The Dll function MsgEncode will allocmem to pOut param, and the BlockFree is used to free the memory which alloced by MsgEncode.</p>
  
  <p>My question is: <strong>How can I use this dll in C#? I'm a newbie in C#.</strong></p>