Comment utiliser Dll Delphi(avec type PChar) en C#

Voici le Delphi code de la DLL:

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]) < 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 > 0;
end;

procedure BlockFree(Buf: pchar); stdcall;
begin
  if assigned(Buf) then
     FreeMem(Buf);
end;

exports
  MsgEncode,
  BlockFree;

begin
end.

La fonction de Dll MsgEncode sera allocmem à la moue param, et la BlockFree est utilisée pour libérer la mémoire qui alloced par MsgEncode.

Ma question est: Comment puis-je utiliser cette dll en C#? Je suis un débutant en C#.

Quelle VERSION de Delphi? (Très important)

OriginalL'auteur Leo | 2011-02-23