Solved

big dll prblem plz help..

Posted on 2001-06-24
35
274 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:krydea
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
gy's i don't have a glu plz help...
and make a example...
plz
0
 

Author Comment

by:krydea
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
this does not work: Form1.ParentWnd := GetDesktopWindow
0
 
LVL 1

Expert Comment

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

Author Comment

by:krydea
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:krydea
Comment Utility
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
Comment Utility
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
Comment Utility
inside...
it would be nice if i can make a onread..
0
 

Author Comment

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

Author Comment

by:krydea
Comment Utility
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
Comment Utility
plz help...
0
 
LVL 1

Expert Comment

by:Kristian
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
plz respone....
0
 

Author Comment

by:krydea
Comment Utility
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
Comment Utility
NNNNNNOOOOOOOOO it doesn't work...the app just crasch...
0
 
LVL 1

Accepted Solution

by:
Kristian earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
**** it;-)
here are your ponts thanx for helping me..
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 40
select query - oracle 16 81
FMX and jaudiotracker playing memory stream 29 29
SUM 2 INTEGER ARRAYS INTO 1 10 53
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now