Pinging from Windows 7 (32-bit)??

Pinging from Windows 7 (32-bit)??

Postby bradmaudlin » Wed Oct 19, 2011 2:52 pm

I am using a Ping(DestinationAddress) Function I found on this forum. It works great in XP, but hangs the program in Windows 7 32-bit. Here is the function and the results that are displayed.

Code: Select all  Expand view
Function Ping(DestinationAddress)  // String in IPv4 Format (192.168.0.1)
   local IcmpHandle,Replicas
   local nAddress := 0             // Numeric IPv4 after inet_addr()
   local RequestData:="Test ping",;
         RequestSize:=15,;
         RequestOptions:="",;
         ReplyBuffer:=space(278),;
         ReplySize:=278,;
         Timeout:=500 // Milliseconds
   DestinationAddress:=left(alltrim(DestinationAddress)+space(15),15)
   olbx:Add("DestinationAddress="+DestinationAddress)
   olbx:REFRESH()
   nAddress := inet_addr(DestinationAddress)
   olbx:Add("nAddress="+Str(nAddress))
   olbx:REFRESH()
   IcmpHandle:=IcmpCreateFile()
   olbx:Add("IcmpHandle="+Str(IcmpHandle))
   olbx:REFRESH()
   Replicas:=IcmpSendEcho(IcmpHandle,;      // Application Hangs Here
                          nAddress,;
                          RequestData,;
                          RequestSize,;
                          0,;
                          ReplyBuffer,;
                          ReplySize,;
                          Timeout)

   olbx:Add("Replicas="+Str(Replicas))
   olbx:REFRESH()
   IcmpCloseHandle(IcmpHandle)

return Replicas

DLL32 FUNCTION WSAGetLastError() AS _INT PASCAL FROM "WSAGetLastError" LIB "ws2_32.dll"
DLL32 FUNCTION inet_addr(cIP AS STRING) AS LONG PASCAL FROM "inet_addr" LIB "ws2_32.dll"
//DLL32 FUNCTION IcmpCreateFile() AS LONG PASCAL FROM "IcmpCreateFile" LIB "icmp.dll"
//DLL32 FUNCTION IcmpCloseHandle(IcmpHandle AS LONG) AS LONG PASCAL FROM "IcmpCloseHandle" LIB "icmp.dll"
//DLL32 FUNCTION IcmpSendEcho(IcmpHandle AS LONG,;
//                            DestinationAddress AS LONG,;
//                            RequestData AS STRING,;
//                            RequestSize AS LONG,;
//                            RequestOptions AS LONG,;
//                            ReplyBuffer AS LPSTR,;
//                            ReplySize AS LONG,;
//                            Timeout AS LONG) AS LONG PASCAL FROM "IcmpSendEcho" LIB "icmp.dll"

DLL32 FUNCTION IcmpCreateFile() AS LONG PASCAL FROM "IcmpCreateFile" LIB "iphlpapi.dll"
DLL32 FUNCTION IcmpCloseHandle(IcmpHandle AS LONG) AS LONG PASCAL FROM "IcmpCloseHandle" LIB "iphlpapi.dll"
DLL32 FUNCTION IcmpSendEcho(IcmpHandle AS LONG,;
                            DestinationAddress AS LONG,;
                            RequestData AS STRING,;
                            RequestSize AS LONG,;
                            RequestOptions AS LONG,;
                            ReplyBuffer AS LPSTR,;
                            ReplySize AS LONG,;
                            Timeout AS LONG) AS LONG PASCAL FROM "IcmpSendEcho" LIB "iphlpapi.dll"


 


The XP Results are:
DestinationAddress = 10.10.1.254
nAddress = -33486326
IcmpHandle = 1880
Replicas = 1

The Windows 7 Pro (32-bit) Results are:
DestinationAddress = 10.10.1.254
nAddress = -33486326
IcmpHandle = 2075472
Replicas = (Program hangs and never returns Replicas)

I have tried both icmp.dll and iphlpapi.dll with the same results.
I have turned off all Firewalls and disable IPv6 on the Win 7 PC.
Is there a different .dll to use on Win 7. Both dll's are in Windows 7.

Has anyone else had this problem??

Thanks,
Brad.
Using FHW+xHarbour+BCC.
bradmaudlin
 
Posts: 27
Joined: Fri Jan 11, 2008 9:58 pm
Location: St Joe, MO

Re: Pinging from Windows 7 (32-bit)??

Postby nnicanor » Wed Oct 19, 2011 9:06 pm

Hello,

This function crash in windows 7 and Windows 8 use solution by Daniel Garcia In this link.

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=20679&hilit=ping

I tested both and works fine in Windows 8 too.

Regards,

Nicanor
Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
nnicanor
 
Posts: 302
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: Pinging from Windows 7 (32-bit)??

Postby bradmaudlin » Thu Oct 20, 2011 7:10 pm

Finally fixed and working in Winows 7.
Thanks for the code samples, they were great.
I had to do a LoadLib32("iphlpapi.dll") to get it to work in Windows 7 and it worked in XP without it. ??????

Thanks,

Brad.
bradmaudlin
 
Posts: 27
Joined: Fri Jan 11, 2008 9:58 pm
Location: St Joe, MO


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests