Einzelnen Beitrag anzeigen

Sascha_OW

Registriert seit: 4. Aug 2005
Ort: Owschlag
129 Beiträge
 
Delphi 2005 Professional
 
#4

Re: Dll benutzen in einer Consolen Anwendungen

  Alt 7. Feb 2006, 08:56
Hallo,

ich habe das gleiche Problem. Will ne FTP DLL Schreiben vileicht kann mir ja jemand helfen

IN der DLL:
Delphi-Quellcode:
library Project2;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }


uses
  SysUtils,
  Classes,
  IdFTP;

{$R *.res}

function FTPConnect (Server: String; User: String; PWDFTP: String): boolean; stdcall;
var con : TIDFTP;
begin
   con := TIDFTP.Create;
   con.Host := Server;
   con.Username := User;
   con.Password := PWDFTP;
   con.Connect;
   IF con.Connected then result := true else result := false;
end;


end.


und dann im Program selbst, die Unit wo die DLL eingebunden wird:

Delphi-Quellcode:
unit Unit2;

interface
   function FTPConnect (Server: String; User: String; PWDFTP: String): boolean; stdcall;
implementation
   function FTPConnect (Server: String; User: String; PWDFTP: String): boolean; stdcall;
external 'project2.dll';
end.
und dann die Unit wo ich die Function aufrufe:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdExplicitTLSClientServerBase, IdFTP, StdCtrls, ExtCtrls, unit2;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  connec: boolean;
implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  connec := FtpConnect ('**************', '************', '***********');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   connec := false;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  IF Connec then Label1.Color := clgreen else Label1.Color := CLRed;
end;

end.
Vielen Dnake vieleicht kann mir ein helfen
















Edit by Sascha:


hat sich erledigt, habe es selbst gefunden, es war das exports was fehlte und eimn begin
Sascha Schwarz
  Mit Zitat antworten Zitat