Thema: Delphi C++ Dll in Delphi

Einzelnen Beitrag anzeigen

jst69

Registriert seit: 19. Sep 2007
2 Beiträge
 
#4

Re: C++ Dll in Delphi

  Alt 19. Sep 2007, 09:49
Bingo so funktionierts! Besten Dank!

Hier mein Code:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
        
  procedure DllMessage; external 'IBANKernel.dll'

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
type
  TIBANProc = function(
  pszKonto: PChar;
  pszBCPC: PChar;
  pszIBAN: PChar;
  nIBANLen: Integer;
  pszBC: pChar;
  nBCLen: Integer;
  pszPC: pChar;
  nPCLen: Integer;
  pszBIC: pChar;
  nBICLen: Integer
): Integer; cdecl;

var
  hDLL: THandle; // Handle zur DLL
  iRes: integer; // Ergebnis der Funktion
  FarProc: TIBANProc;
  sDLLPath: PAnsiChar;
  pszKonto,pszBCPC,pszIBAN,pszBC,pszPC,pszBIC: pChar;
  nIBANLen,nBCLen,nPCLen,nBICLen: integer;
begin
  sDLLPath := PChar(ExtractFilePath(Application.ExeName) + 'IBANKernel.dll');
  hDLL := LoadLibrary(sDLLPath);
  if hDLL = 0 then begin
    ShowMessage('DLL konnte nicht geladen werden.');
    Exit;
  end;

  try
    pszKonto := pChar(edit2.Text);
    pszBCPC := pChar(edit1.Text);
    pszIBAN := nil;pszIBAN := StrAlloc(20);
    nIBANLen := 21;
    pszBC := nil;pszBC := StrAlloc(20);
    nBCLen := 10;
    pszPC := pChar('100');pszPC := StrAlloc(20);
    nPCLen := 10;
    pszBIC := nil;pszBIC := StrAlloc(20);
    nBICLen := 10;
    iRes := 0;
    @FarProc := GetProcAddress(hDLL, 'IT_IBANConvert');
    if Assigned(@FarProc) then
    begin
      iRes := FarProc(pszKonto,pszBCPC,pszIBAN,nIBANLen,pszBC,nBCLen,pszPC,nPCLen,pszBIC,nBICLen);
      edit3.Text := pszPC;
      edit4.Text := pszIBAN;
      edit5.Text := IntToStr(iRes);
    end;
    //ShowMessage('Bingo-->'+pszKonto+'-->'+pszBCPC+'-->'+pszIBAN+'------->'+IntToStr(iRes));

    FreeLibrary(hDLL);
  except
    ShowMessage('Funktion der DLL konnte nicht ausgeführt werden.');
  end;
end;

end.
NB: Ich weiss, StrDispose() fehlt noch

[edit=SirThornberry]Bitte, bitte, bitte, bitte setzte nächstes mal selbst die Delphi-Tags damit der Quelltext lesbar ist - Mfg, SirThornberry[/edit]
  Mit Zitat antworten Zitat