Solved

Standared App to Dll?????

Posted on 2002-03-23
4
307 Views
Last Modified: 2010-04-04
This code works as a .Exe  How can i use this code in a DLL...
--------------------------


unit Main;

interface

uses
  {$IFDEF Linux}
  QGraphics, QControls, QForms, QDialogs, QStdCtrls, QExtCtrls,
  {$ELSE}
  windows, messages, graphics, controls, forms, dialogs, stdctrls, extctrls,
  {$ENDIF}
  SysUtils, Classes, IdIcmpClient, IdBaseComponent, IdComponent, IdRawBase, IdRawClient;


type
  TfrmPing = class(TForm)
  lstReplies: TListBox;
  ICMP: TIdIcmpClient;
    Panel1: TPanel;
    btnPing: TButton;
    edtHost: TEdit;
    Label1: TLabel;
  procedure btnPingClick(Sender: TObject);
  procedure ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
    procedure FormCreate(Sender: TObject);
  private
  public
  end;

var
  frmPing: TfrmPing;

implementation
{$IFDEF MSWINDOWS}{$R *.dfm}{$ELSE}{$R *.xfm}{$ENDIF}

procedure TfrmPing.btnPingClick(Sender: TObject);
var
  i: integer;
begin
  ICMP.OnReply := ICMPReply;
  ICMP.ReceiveTimeout := 1000;
  btnPing.Enabled := False; try
  ICMP.Host := edtHost.Text;
  for i := 1 to 4 do begin
  ICMP.Ping;
  Application.ProcessMessages;
  //Sleep(1000);
  end;
  finally btnPing.Enabled := True; end;
end;

procedure TfrmPing.ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
var
  sTime: string;
begin
  // TODO: check for error on ping reply (ReplyStatus.MsgType?)
  if (ReplyStatus.MsRoundTripTime = 0) then
  sTime := '<1'
  else
  sTime := '=';

  lstReplies.Items.Add(Format('%d bytes from %s: icmp_seq=%d ttl=%d time%s%d ms',
  [ReplyStatus.BytesReceived,
  ReplyStatus.FromIpAddress,
  ReplyStatus.SequenceId,
  ReplyStatus.TimeToLive,
  sTime,
  ReplyStatus.MsRoundTripTime]));

end;

end.

////////////////////////
0
Comment
Question by:Dinkleburger
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 30 total points
ID: 6893346
library pingDll;

{ 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
  QGraphics,
  QControls,
  QForms,
  QDialogs,
  QStdCtrls,
  QExtCtrls,
  windows,
  messages,
  graphics,
  controls,
  forms,
  dialogs,
  stdctrls,
  extctrls,
  SysUtils,
  Classes,
  IdIcmpClient,
  IdBaseComponent,
  IdComponent,
  IdRawBase,
  IdRawClient;

type
 TfrmPing = class(TForm)
 lstReplies: TListBox;
 ICMP: TIdIcmpClient;
   Panel1: TPanel;
   btnPing: TButton;
   edtHost: TEdit;
   Label1: TLabel;
 procedure btnPingClick(Sender: TObject);
 procedure ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
 procedure FormCreate(Sender: TObject);
 private
 public
 end;

var
 frmPing: TfrmPing;

{$IFDEF MSWINDOWS}{$R *.dfm}{$ELSE}{$R *.xfm}{$ENDIF}

procedure TfrmPing.btnPingClick(Sender: TObject);
var
 i: integer;
begin
 ICMP.OnReply := ICMPReply;
 ICMP.ReceiveTimeout := 1000;
 btnPing.Enabled := False; try
 ICMP.Host := edtHost.Text;
 for i := 1 to 4 do begin
 ICMP.Ping;
 Application.ProcessMessages;
 //Sleep(1000);
 end;
 finally btnPing.Enabled := True; end;
end;

procedure TfrmPing.ICMPReply(ASender: TComponent; const ReplyStatus: TReplyStatus);
var
 sTime: string;
begin
 // TODO: check for error on ping reply (ReplyStatus.MsgType?)
 if (ReplyStatus.MsRoundTripTime = 0) then
 sTime := '<1'
 else
 sTime := '=';

 lstReplies.Items.Add(Format('%d bytes from %s: icmp_seq=%d ttl=%d time%s%d ms',
 [ReplyStatus.BytesReceived,
 ReplyStatus.FromIpAddress,
 ReplyStatus.SequenceId,
 ReplyStatus.TimeToLive,
 sTime,
 ReplyStatus.MsRoundTripTime]));
end;

Procedure CreatePingForm;stdcall;  ///NOTE the exposed function
begin
   frmPing:=TfrmPing.Create(Application);
   frmPing.ShowModal;
end;

Exports CreatePingForm;



begin
end.
{******************************************}


In your app:


implementation
procedure CreatePingForm;stdcall external 'pingdll.dll';
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 CreatePingForm;
end;



Good luck!!


0
 

Author Comment

by:Dinkleburger
ID: 6893916



This is where i cant get past at the moment

 CASE IDNum OF
 1: TfrmPing.
////// I need the Case Id Num 1 to point or activate the Procedure Below.
in the Dll


procedure TfrmPing.btnPingClick(Sender: TObject);

thanks
0
 

Author Comment

by:Dinkleburger
ID: 6894039
Yes the Dll is communicating with the Pchar
Just going over things i see that the app is being created by the Dll...i think!!

My mistake i didnt explain well enough... what i meant to say is i want the procedures and functions from the Application

and be able to use them in My DLL...

so the Application.EXE never runs or shows its User interface

My DLL is called and the functions from the Application are used and return infomation from the DLL back to the program that called the DLL

Thats where the CASE IDNum comes in


CASE IDNum

1: Ping
2: ect ect
3 ect ect ect...


The outside Program Calling the DLL
the user clicks on a menu button that say PING
this corresponds with the CASE IDNum 1 Ping
and then executes the Procedure Ping;
in the DLL

the procedure then returns the result back to the Program that originally called the DLL

hope this makes more sense

*smiles*


0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6975832
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20267246.html
http://www.experts-exchange.com/questions/Q.20279387.html
http://www.experts-exchange.com/questions/Q.20279679.html
http://www.experts-exchange.com/questions/Q.20280760.html
http://www.experts-exchange.com/questions/Q.20281381.html
http://www.experts-exchange.com/questions/Q.20280833.html
http://www.experts-exchange.com/questions/Q.20294654.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

707 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

17 Experts available now in Live!

Get 1:1 Help Now