Wie verwenden von Delphi-Dll(mit PChar-Typ) in C#

Hier ist der Delphi-DLL-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]) < 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.

Die Dll-Funktion MsgEncode wird allocmem zu schmollen, param, und die BlockFree wird verwendet, um den Speicher frei, die alloced von MsgEncode.

Meine Frage ist: Wie kann ich diese dll in C#? Ich bin ein Neuling in C#.

Welche VERSION von Delphi? (Sehr wichtig)

InformationsquelleAutor Leo | 2011-02-23

Schreibe einen Kommentar