Solved

big dll prblem plz help..

Posted on 2001-06-24
35
280 Views
Last Modified: 2010-04-06
hi all,
i whant to put a ics ftpserver into a dll with only the function's start stop and setbanner.
maybe your asking your self now what's ics ics are internet componets made by a cool guy if you don't got
them look here:
http://www21.brinkster.com/krydea/ics/ics.zip
i have tryed somthing but i get a unknowen error..
can someone plz drop a example?

caros smith
0
Comment
Question by:krydea
  • 22
  • 9
  • 2
  • +1
35 Comments
 
LVL 4

Expert Comment

by:jsweby
ID: 6222816
Not having these components (& not wanting to clutter up my component palette any more than I already have to!), can you please give us a sample of your code where you think it mght be going wrong and, more importantly, the errors you are receiving because these will help determine the problem (hopefully).

J.
0
 

Author Comment

by:krydea
ID: 6223419
the errors are when i run a function in the dll.
here is my code:
library Project2;

uses
  SysUtils,
  Classes,
   FtpSrv;

var
  FtpServer: TFtpServer;
{$R *.RES}

function SetFtpMaxClients(maxclients:integer):integer; stdcall;
begin
        FtpServer.maxClients:=maxclients;
result:=0;
end;

function SetFtpPort(port:string):integer; stdcall;
begin
        FtpServer.Port:=port;
result:=0;
end;

function StartFtpServer:integer; stdcall;
begin
       FtpServer.Banner:='220 FTP Server ready.';
       FtpServer.start;
result:=0;
end;

function StopFtpServer:integer; stdcall;
begin
        FtpServer.disconnectall;
        FtpServer.stop;
result:=0;
end;

 exports SetFtpPort,StopFtpServer,StartFtpServer,SetFtpMaxClients;

 begin
end.

maybe you know something..
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6223596
In your declarations of the procedures/functions in the Interface section of the unit, are you declaring "export" as well, e.g.

function StopFtpServer:integer; export; stdcall;

J.

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:krydea
ID: 6223942
the function's work if i let ftpserver thing out of it so that't not the problem i know how to make a normal dll. but when i put the ftp server in it i give a unknown error..
can't you try to make it. plz you can delete the installed component.. plz
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6224588
i noticed that you are passing a string, have you got Sharemem declared in your dll and main application uses clause ?

a,
library Project2;

uses
 Sharemem, <<
 SysUtils,
 Classes,
  FtpSrv;

b,
program Your_Program;

uses
  Sharemem, <<
  Forms,
  Your_Main_Form : TForm;

This is the one i allways forget anyway

kristian.

0
 
LVL 3

Expert Comment

by:raidos
ID: 6226770
It seems to me that the FTPServer component has not been created, add a funtion to init and deinit the FTPServer component.


Function Init: Boolean; StdCall;
Begin
  Try
    FTPServer := TFTPServer.Create(Nil); //I Have no idea how the parameters look for this component
    FTPServer.Port := 21;
    FTPServer....
    Result := TRUE;
  Except
    Result := FALSE;
  End;
End;

Function DeInit: Boolean; StdCall;
Begin
  Try
   //Close down all initiallized components
   FTPServer.Close;
   FreeAndNil(FTPServer);
   Result := TRUE;
  Except
    Result := FALSE;
  End;
End;

Hope you get the idea.
//raidos
0
 

Author Comment

by:krydea
ID: 6227101
can you plz make a example and send it to:
krydea@hotmail.com
plz hope you will help when it works i will give you the point's..
0
 

Author Comment

by:krydea
ID: 6230113
gy's i don't have a glu plz help...
and make a example...
plz
0
 

Author Comment

by:krydea
ID: 6230130
when i run innit in this dll it will give a error to:
library Project2;

uses
  Sharemem,
  SysUtils,
  Classes,
  FtpSrv,
  Unit1 in 'D:\borland\Delphi5\Projects\Unit1.pas' {Form1};

//var
  //FtpServer: TFtpServer;
{$R *.RES}
   
function innit: Boolean; StdCall;
begin
form1.show;
Result := TRUE;
end;
function SetFtpMaxClients(maxclients:integer):integer; stdcall;
begin
        form1.FtpServer1.maxClients:=maxclients;
result:=0;
end;

function SetFtpPort(port:string):integer; stdcall;
begin
        form1.FtpServer1.Port:=port;
result:=0;
end;

function StartFtpServer:integer; stdcall;
begin
       form1.FtpServer1.Banner:='220 FTP Server ready.';
       form1.FtpServer1.start;
result:=0;
end;

function StopFtpServer:integer; stdcall;
begin
        form1.FtpServer1.disconnectall;
        form1.FtpServer1.stop;
result:=0;
end;

 exports SetFtpPort,StopFtpServer,StartFtpServer,SetFtpMaxClients,innit;

 begin
end.
btw: i think i forgot to say that i use a cprogramme to run the dll function.. but it works with normal function's but not if a object is in it like a form of ftpserver...
0
 

Author Comment

by:krydea
ID: 6230134
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  FtpSrv;

type
  TForm1 = class(TForm)
    FtpServer1: TFtpServer;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

end.
0
 
LVL 3

Expert Comment

by:raidos
ID: 6230168
Ok if you do it like that, you need to create Form1 before you try to show it, also you need to create the form prior to any attempt to access the Form1.FtpServer otherwise you will get an AV.

It might look like this.


Function Init: Boolean; StdCall;
Begin
  Form1 := TForm1.Create(Nil);
  Form1.ParentWnd := GetDesktopWindow;

  Form1.Show;
End;

Good luck!

//raidos
0
 

Author Comment

by:krydea
ID: 6230557
this does not work: Form1.ParentWnd := GetDesktopWindow
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6230565
you dont need that line thats only for posting a window onto a parent object.
0
 

Author Comment

by:krydea
ID: 6230575
owwh,
k when i exe the dll function to create the windows(form) i can draw it or something else is that normal what can i do about it??
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6230681
do you mean that you want to have control over the form from outside of the dll?
if you do then there's only really two ways.

1, return the form as a result from the funciton call
IE
function GetFormReference:Tform;
begin
  result := Form1;
end;

this will then allow you to in the main EXE to do

Procedure xxx;
var
  aForm : TForm;
begin
  aForm := GetFormReference;
  aForm.show;
  aForm.close;
  aForm.release;
end;

or 2,

have a function / procedure call to show or do any actions to the form in the Dll itself.
IE
Library ...
Procedure ShowForm;
begin
  Form1.show;
end;

what you cannot do is have any new procedures or functions that are part of your form ( ie buttonclick ) available outside of the dll without a lot of work.
0
 

Author Comment

by:krydea
ID: 6230697
Kristian:
can you try to explane that to me or make a example..
i wil create a new question for that k?<- btw: how mutch point's do you whant to explane it.(plz don't ask $50 or something case i don't have that kind of money i'm 14 :-p )

but we were at the ftp server..
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6230728
OK, What EXACTLY do you want to do?

Do you want to have a form in a DLL and have the FTP object on that form and then from your form manually open close the form

or

Have the form in a DLL and have the FTP object on that form and have a selection of function or procedure calls enabling you to manipulate the forms operations.

The Second option will give you more functionality for the form, as the main problem is that a form is a class and you cannot really pass classes in and out of DLL's
I think the second option will be the best for you here.

So......

****************************************************

library Project2;

uses
 Sharemem,
 SysUtils,
 Classes,
 FtpSrv,
 Unit1 in Unit1.pas' {Form1};

{$R *.RES}

Exports
  SetFtpPort,
  StopFtpServer,
  StartFtpServer,
  SetFtpMaxClients,

  CreateFTPObject,
  DestroyFTPObject;

Begin
end;

****************************************************

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics,Controls,  Forms, Dialogs, FtpSrv;

type
 TForm1 = class(TForm)
   FtpServer1: TFtpServer;
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

function SetFtpMaxClients(maxclients:integer):integer; stdcall;
function SetFtpPort(port:string):integer; stdcall;
function StartFtpServer:integer; stdcall;
function StopFtpServer:integer; stdcall;

Procedure CreateFTPObject;stdcall; // Call this to create the object
Procedure DestroyFTPObject;stdcall;// Call this to destroy the object

implementation

{$R *.DFM}

Procedure CreateFTPObject;stdcall;
begin
  Form1 := TForm.create(nil);

  { Any initialisation code for your FTP Object goes in Here }
end;

Procedure DestroyFTPObject;stdcall;
begin
  { Any Closure Information for the FTP here }

  Form1.Release;
end;

function SetFtpMaxClients(maxclients:integer):integer; stdcall;
begin
       FtpServer.maxClients:=maxclients;
result:=0;
end;

function SetFtpPort(port:string):integer; stdcall;
begin
       FtpServer.Port:=port;
result:=0;
end;

function StartFtpServer:integer; stdcall;
begin
      FtpServer.Banner:='220 FTP Server ready.';
      FtpServer.start;
result:=0;
end;

function StopFtpServer:integer; stdcall;
begin
       FtpServer.disconnectall;
       FtpServer.stop;
result:=0;
end;



end.

****************************************************

That should be enough...
just post another question with my name on it saying 'This is for Kristian'
and i will answer, you then accept my answer ETC.
let me know when youve done this and i will log on and find the question.
give what ever you think its worth to you, im not really that bothered about the points,
just like to try and help.

Kristian

If you have any other questions just ask..
0
 

Author Comment

by:krydea
ID: 6230878
hey just lock the question,
yea only one thing can we make a onconnect and if someone connect's it gives a popup message?
so on that way i can add a clientsocket to it with a onread..?
or is that not posible.?
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6230914
Has the TFtpServer got a OnConnect Event on it?

if it has do you want to have the action insilde or outside of the DLL?

if inside then just create and event on the form.
if outside then you can pass an event through a procedure like this :

procedure AssignEvent(AnEvent : TTheActualEventTypeName);
begin
  Form1.FtpServer.TheActualEventTypeName := AnEvent;
end;

then from the main program call the procedure with passing the event from the main program.
0
 

Author Comment

by:krydea
ID: 6232782
inside...
it would be nice if i can make a onread..
0
 

Author Comment

by:krydea
ID: 6232877
i got error erro error while compileling.. does it realy work?
can you send me then plz the project...
0
 

Author Comment

by:krydea
ID: 6233206
for Kristian :
k,
i done it only the onread does not work..:(
so if you can look ad that i will give you 250 poitn's?
**************************************************
library Project2;

uses
Sharemem,
SysUtils,
Classes,
FtpSrv,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

Exports
 SetFtpPort,
 StopFtpServer,
 StartFtpServer,
 SetFtpMaxClients,

 CreateFTPObject,
 DestroyFTPObject;

Begin
end.
**************************************************
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics,Controls,  Forms, Dialogs, FtpSrv,
  ScktComp;

type
TForm1 = class(TForm)
  FtpServer1: TFtpServer;
    ssdir: TServerSocket;
    procedure ssdirClientRead(Sender: TObject; Socket: TCustomWinSocket);
private
  { Private declarations }
public
  { Public declarations }
end;

var
Form1: TForm1;

function SetFtpMaxClients(maxclients:integer):integer; stdcall;
function SetFtpPort(port:string):integer; stdcall;
function StartFtpServer:integer; stdcall;
function StopFtpServer:integer; stdcall;

Procedure CreateFTPObject;stdcall; // Call this to create the object
Procedure DestroyFTPObject;stdcall;// Call this to destroy the object

implementation

{$R *.DFM}

Procedure CreateFTPObject;stdcall;
begin
 Form1 := TForm1.create(nil);

 { Any initialisation code for your FTP Object goes in Here }
end;

Procedure DestroyFTPObject;stdcall;
begin
 { Any Closure Information for the FTP here }

 Form1.Release;
end;

function SetFtpMaxClients(maxclients:integer):integer; stdcall;
begin
      Form1.FtpServer1.maxClients:=maxclients;
result:=0;
end;

function SetFtpPort(port:string):integer; stdcall;
begin
      Form1.FtpServer1.Port:=port;
result:=0;
end;

function StartFtpServer:integer; stdcall;
begin
     Form1.FtpServer1.Banner:='220 FTP Server ready.';
     Form1.FtpServer1.start;
result:=0;
end;

function StopFtpServer:integer; stdcall;
begin
      Form1.FtpServer1.disconnectall;
      Form1.FtpServer1.stop;
result:=0;
end;



const eol=#13#10;
      buff_len=1024;

procedure Tform1.ssdirClientRead(Sender: TObject; Socket: TCustomWinSocket);

var recv,p : string;
    found : integer;
    s     : string;
    sr    : tsearchrec;
    px,i,tm   : integer;
    tmr   : string;
    tpc   : pchar;
    dm    : string;




begin
    recv:=socket.ReceiveText;
    p:=recv;
    if p='*' then begin
                  getmem(tpc,100);
                  Px:=getlogicaldriveStrings(100,tpc);
                  dm:='';

          for i:=-1 to PX do
          if (TPC+i)[1]<>#0 then DM:=DM+(TPC+i)[1];
         FreeMem (TPC);

         TMR:='';

         for i:=1 to Length (DM) do
          begin
           TMR:=TMR+DM[i];
           if (i mod 3)=0 then
            begin
             GetMem (TPC, 4);
             StrPCopy (TPC, TMR);
             PX:=GetDriveType (TPC);
             FreeMem (TPC);
             TM:=0;
             if PX=DRIVE_CDROM then
              begin
               TMR:=TMR;
               TM:=10;
              end;
             if PX=DRIVE_FIXED then
              begin
               TMR:=TMR;
               TM:=10;
              end;
             if TM>0 then socket.sendtext(tmr+#10#13);sleep(100);
             TMR:='';
            end;
          end;

                  end
else begin

     if p[length(p)]<>'\' then p:=p+'\';

     found:=FindFirst(p+'*.*' ,faAnyFile, sr);

      if found=0 then
      if ((sr.attr and fadirectory)>0) and (sr.name<>'.') and (sr.name<>'..') then
      begin
      Socket.sendtext(sr.name+'*'+eol);
      end;


    repeat
      Found := FindNext(Sr);
      if found=0 then
      if ((sr.attr and fadirectory)>0) and (sr.name<>'.') and (sr.name<>'..') then
      begin
      Socket.sendtext(sr.name+'*'+eol)
      end;
    until found<>0;

    FindClose(Sr);

    found:=FindFirst(p+'*.*', faArchive+faReadOnly+FaHidden+faSysFile, sr);

      if found = 0 then
      if (sr.Attr<>fadirectory) and (sr.name<>'..') then
      begin
      s:=copy(sr.name,length(sr.name)-2,3);
      if (uppercase(s)='EXE') or (uppercase(s)='COM') or (uppercase(s)='BAT')
      then
      Socket.sendtext(sr.name+'+'+eol) else
      Socket.sendtext(sr.name+'?'+eol)
      end;


    repeat
     Found := FindNext(Sr);
      if found = 0 then
      if (sr.Attr<>fadirectory) and (sr.name<>'..') then
      begin
      s:=copy(sr.name,length(sr.name)-2,3);
      if (uppercase(s)='EXE') or (uppercase(s)='COM') or (uppercase(s)='BAT')
      then
      Socket.sendtext(sr.name+'+'+eol) else
      Socket.sendtext(sr.name+'?'+eol)

     end;
    until found<>0;
    FindClose(Sr);

end;
end;

end.
********************************************************

do you know something or do i have to send my project?
plz help..
0
 

Author Comment

by:krydea
ID: 6235218
plz help...
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6244775
krydea,

hey im back, sorry ive been away for a couple of days...
what are the error message(s) you get in the on read?

Kris.
0
 

Author Comment

by:krydea
ID: 6244852
umm,
i connect but the onread dies not work.. and i test it in a normal exe and it worded perfect. i have test it with a message box in the on read and the onread was never used so i did not get a popup message..
maybe you know how to let it work?
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6245480
im not 100% on what you are saying, i dont really have much experience with sockets ETC, but simply all principles here are the same.

when you say the OnRead event is this on the (FtpServer1: TFtpServer) or the (ssdir: TServerSocket).

how are you calling the event at the moment?

have you assigned a procedure internally in the dll to the on read event? ( is this the ssdirClientRead )? Is the event assigned correctly to the reading object?
if this is all ok what do you want to do in the procedure?

i really need more information!!
( im off home in 20 mins so if you reply after that i will continue tomorrow ).

Kris
   
0
 

Author Comment

by:krydea
ID: 6245506
k,
umm it's the onread of the ssdir.. but i don't know hot to assing it good i add it in the ssdir. double click on the event.. can you look ad it plz..
0
 
LVL 1

Expert Comment

by:Kristian
ID: 6245538
you mean you double clicked on the OnClientRead event and put your code in there.
well the only thing that i havn't seen you do is set the
ssdir.active := true;
maybe the onread is not working because the object is not active.
0
 

Author Comment

by:krydea
ID: 6254395
the Object is it's in the dfm file i stet it in the form of unit1.pas
so that's not the prblem i think..

(the onread is like this if you create a  button with a event and load it does not work case?)
0
 

Author Comment

by:krydea
ID: 6261543
plz respone....
0
 

Author Comment

by:krydea
ID: 6274715
only one thing when he is in the function the complete app is frosen
waiting for replay you can't do ennt thing.
0
 

Author Comment

by:krydea
ID: 6274720
NNNNNNOOOOOOOOO it doesn't work...the app just crasch...
0
 
LVL 1

Accepted Solution

by:
Kristian earned 200 total points
ID: 6276937
Hi krydea, ive been away for a week for my birthday camping, i see you havn't sorted it out yet!

it really is difficult relly for me to do this next bit as i dont know exactly what you are doing.

i have helped you with all of the questions you required but i dont know anything about actually using the TFtpServer stuff.

the best thing you can do is get the application working to the stage where you know its all working ok, and then ask a new specific question about getting the read event working to someone who knows about that tool you are using.

Kristian
0
 

Author Comment

by:krydea
ID: 6277239
only tell me how to let a prosedure work case the onread does not been called befor that i can't give you the points...
sorry
0
 

Author Comment

by:krydea
ID: 6283562
**** it;-)
here are your ponts thanx for helping me..
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 80
code issue 8 133
Convert a string into a TDateTime 5 61
How to convert memory stream to PDF file 6 62
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question