Squeebee
asked on
Need to call ping32.dll from an InnoSetup script
Hi All,
I need to call the ping32.dll library from within an innosetup code section, which uses pascal. Problem is I don't know pascal and do not know how to call a dll.
There is an example of pascal in Innosetup calling an ODBC dll at http://www13.brinkster.com/vincenzog/isxart.asp?idart=52
The DLL call is defined in VB as follows (zip file that includes the ping32.dll package at http://www.winnetmag.com/Files/562/562.zip):
Declare Function ping _
Lib "ping32.dll" _
(ByVal sHostName$, _
ByVal sIPAddr$, _
ByVal iDataLen%, _
lPingTime&, _
ByVal iTimeout%, _
ByVal iVerbose%) As Integer
With the following writeup:
--------------------------
The first parameter of the ping function is a string containing either the name or the IP address of the system to be pinged. The second parameter is a string that the ping function returns. This string contains the IP address of the pinged system. This parameter lets the calling program retrieve the IP address for a given TCP/IP host name. The third parameter specifies the size of the data packet sent with the ping. The maximum data length that ping32.dll allows is 1024 bytes. The fourth parameter, a long variable, returns the elapsed milliseconds the ping function required to execute. The fifth parameter contains the maximum time in milliseconds that the ping function waits for a response for sent or received packets. The sixth parameter specifies the mode of operation for the ping function. If you set this parameter to True, ping32.dll runs in verbose mode, the mode that displays all ping results and errors in a message box. Setting the sixth parameter to False runs ping32.dll in silent mode, the mode that reports any ping results and errors in the ping function's return code and output parameters.
-------------------------- ---
My last attempt was to call ping.exe directly as follows:
procedure TestOnClick(Sender: TObject);
var
bReturn: boolean;
iResultCode: integer;
sArgs: string;
begin
WizardForm.Enabled := false;
sArgs := '-n 1 ' + txtIPaddress.Text;
Msgbox(sArgs,0,0);
bReturn := InstExec('ping.exe','-n 1' + IPaddress,'',True,False,SW _HIDE,iRes ultCode);
Msgbox(IntToStr(iResultCod e),0,0);
WizardForm.Enabled := true;
end;
I just want to show a yes/no messagebox to inform the user as to whether the IP they provided is live.
I need to call the ping32.dll library from within an innosetup code section, which uses pascal. Problem is I don't know pascal and do not know how to call a dll.
There is an example of pascal in Innosetup calling an ODBC dll at http://www13.brinkster.com/vincenzog/isxart.asp?idart=52
The DLL call is defined in VB as follows (zip file that includes the ping32.dll package at http://www.winnetmag.com/Files/562/562.zip):
Declare Function ping _
Lib "ping32.dll" _
(ByVal sHostName$, _
ByVal sIPAddr$, _
ByVal iDataLen%, _
lPingTime&, _
ByVal iTimeout%, _
ByVal iVerbose%) As Integer
With the following writeup:
--------------------------
The first parameter of the ping function is a string containing either the name or the IP address of the system to be pinged. The second parameter is a string that the ping function returns. This string contains the IP address of the pinged system. This parameter lets the calling program retrieve the IP address for a given TCP/IP host name. The third parameter specifies the size of the data packet sent with the ping. The maximum data length that ping32.dll allows is 1024 bytes. The fourth parameter, a long variable, returns the elapsed milliseconds the ping function required to execute. The fifth parameter contains the maximum time in milliseconds that the ping function waits for a response for sent or received packets. The sixth parameter specifies the mode of operation for the ping function. If you set this parameter to True, ping32.dll runs in verbose mode, the mode that displays all ping results and errors in a message box. Setting the sixth parameter to False runs ping32.dll in silent mode, the mode that reports any ping results and errors in the ping function's return code and output parameters.
--------------------------
My last attempt was to call ping.exe directly as follows:
procedure TestOnClick(Sender: TObject);
var
bReturn: boolean;
iResultCode: integer;
sArgs: string;
begin
WizardForm.Enabled := false;
sArgs := '-n 1 ' + txtIPaddress.Text;
Msgbox(sArgs,0,0);
bReturn := InstExec('ping.exe','-n 1' + IPaddress,'',True,False,SW
Msgbox(IntToStr(iResultCod
WizardForm.Enabled := true;
end;
I just want to show a yes/no messagebox to inform the user as to whether the IP they provided is live.
ASKER
Umm, is there a function header that was not pasted at the top?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try to run the following command and show me the result:
tdump -ee ping32.dll
tdump -ee ping32.dll
ASKER
System does not recognize tdump.
Which compiler do you use?
ASKER
And I get an unknown type: PLONG error when I try to compile my innosetup script.
ASKER
I am useing InnoSetup, Innosetup is written in Delphi and uses a pascal parser to supply customization.
Replace PLONG with PULONG
and
if _imp_ping = nil then begin
with
if @_imp_ping = nil then begin
and
if _imp_ping = nil then begin
with
if @_imp_ping = nil then begin
I have to go now. Sorry.
See you tomorrow.
See you tomorrow.
ASKER
Hmm, didn't like pulong either.
ASKER
Thanks for your help so far.
PULONG is probably
Type
PULONG = ^Cardinal;
But if you include Windows in your uses clause you should have PULONG defined and ready..
Regards
//raidos
Type
PULONG = ^Cardinal;
But if you include Windows in your uses clause you should have PULONG defined and ready..
Regards
//raidos
ASKER
I have absolutely no clue what you are talking about. I have zero pascal knowledge.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
These are not used in an InnoSetup [Code] block. I think I may have to investigate the example of a working InnoSetup dll call and try to modify the suggestions given to work with it.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
These are not used in an InnoSetup [Code] block. I think I may have to investigate the example of a working InnoSetup dll call and try to modify the suggestions given to work with it.
"These are not used in an InnoSetup [Code] block" - well, no, since the zip doesn't contain any Delphi units. What I've posted is a full unit which *calls* the DLL in the way that DLLs are usually called from Delphi, and which includes an *example* of how to use it (a common way of expressing examples in this EE forum). Although Gloomy has posted a *different* way to access the DLL, it's not necessarily the *best* way (to be fair, there are fors and againsts for both methods).
Geoff M.
Geoff M.
Beg your pardon, the *second* zip containing the DLL didin't have any Delphi source. However, the first zip doesn't appear to call the Ping routine anyway... unless I've missed it?
Geoff M.
Geoff M.
ASKER
I found the DLL by looking at a VB example that calls it. There is no delphi or pascal calling it at all, if there was a pascal example in the zip I may have just used it instead of coming here. I am awarding 500 points because I do not know Pascal/Delphi and therefore was looking for a solution I could drop in with little modification.
It's me again.
Are there any problems with my code?
Are there any problems with my code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi everyone,
Thanks for your input. I have split up the points and I am calling Lee_Nover's solution the accepted answer as it relates most directly to my implementation.
Thanks for your input. I have split up the points and I am calling Lee_Nover's solution the accepted answer as it relates most directly to my implementation.
hLib: THandle;
PingTime: longint;
_imp_ping: function(sHostName, sIPAddr: PCHAR; iDataLen: longint; lPingTime: PLONG; iTimeout: longint; iVerbose: longint) : longint; stdcall;
begin
hLib := LoadLibrary ('ping32.dll');
if hLib = 0 then begin
ShowMessage('Load ping32.dll error');
Exit;
end;
@_imp_ping := GetProcAddress ( hLib, 'ping' );
if _imp_ping = nil then begin
ShowMessage('Load func ping error');
Exit;
end;
// Call to the function
_imp_ping('SomeHost', '192.168.1.15', 128, @PingTime, 100, 1);
end;