• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

big dll prblem plz help..

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
krydea
Asked:
krydea
  • 22
  • 9
  • 2
  • +1
1 Solution
 
jswebyCommented:
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
 
krydeaAuthor Commented:
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
 
jswebyCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
krydeaAuthor Commented:
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
 
KristianCommented:
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
 
raidosCommented:
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
 
krydeaAuthor Commented:
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
 
krydeaAuthor Commented:
gy's i don't have a glu plz help...
and make a example...
plz
0
 
krydeaAuthor Commented:
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
 
krydeaAuthor Commented:
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
 
raidosCommented:
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
 
krydeaAuthor Commented:
this does not work: Form1.ParentWnd := GetDesktopWindow
0
 
KristianCommented:
you dont need that line thats only for posting a window onto a parent object.
0
 
krydeaAuthor Commented:
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
 
KristianCommented:
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
 
krydeaAuthor Commented:
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
 
KristianCommented:
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
 
krydeaAuthor Commented:
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
 
KristianCommented:
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
 
krydeaAuthor Commented:
inside...
it would be nice if i can make a onread..
0
 
krydeaAuthor Commented:
i got error erro error while compileling.. does it realy work?
can you send me then plz the project...
0
 
krydeaAuthor Commented:
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
 
krydeaAuthor Commented:
plz help...
0
 
KristianCommented:
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
 
krydeaAuthor Commented:
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
 
KristianCommented:
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
 
krydeaAuthor Commented:
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
 
KristianCommented:
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
 
krydeaAuthor Commented:
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
 
krydeaAuthor Commented:
plz respone....
0
 
krydeaAuthor Commented:
only one thing when he is in the function the complete app is frosen
waiting for replay you can't do ennt thing.
0
 
krydeaAuthor Commented:
NNNNNNOOOOOOOOO it doesn't work...the app just crasch...
0
 
KristianCommented:
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
 
krydeaAuthor Commented:
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
 
krydeaAuthor Commented:
**** it;-)
here are your ponts thanx for helping me..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 22
  • 9
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now