Page 1 of 1

IcmpSendEcho + unicod = not work

Posted: Fri Sep 25, 2015 11:17 am
by registrymechanic22
This code:

Code: Select all

Procedure TestInetConnection()
  SendData$ = "Test"
  ReplyBuffer$ = Space(SizeOf(ICMP_ECHO_REPLY) + Len(SendData$) + SizeOf(character))
  hIcmpFile = IcmpCreateFile_()
  dwRetVal = IcmpSendEcho_(hIcmpFile, inet_addr_("209.85.225.105"), @SendData$, Len(SendData$), #Null, @ReplyBuffer$, Len(ReplyBuffer$) + SizeOf(ICMP_ECHO_REPLY), 1000)

  If dwRetVal
    ProcedureReturn 1
  Else 
    ProcedureReturn 0
  EndIf
  
EndProcedure

Debug TestInetConnection()
If check the checkbox "create unicod application" - does not work...
Help please. What need to do to earn in "unicod"?

Re: IcmpSendEcho + unicod = not work

Posted: Fri Sep 25, 2015 11:50 am
by infratec
Hi,

Code: Select all

EnableExplicit

Procedure TestInetConnection(Address$)
  
  Protected Result.i, hIcmpFile.i, SendData$, ReplyBuffer$, *Buffer
  
  SendData$ = "Test"
  ReplyBuffer$ = Space(SizeOf(ICMP_ECHO_REPLY) + StringByteLength(SendData$) + SizeOf(character))
  
  hIcmpFile = IcmpCreateFile_()
  
  If hIcmpFile
    *Buffer = AllocateMemory(StringByteLength(Address$, #PB_Ascii) + 1)
    If *Buffer
      PokeS(*Buffer, Address$, -1, #PB_Ascii)
      
      If IcmpSendEcho_(hIcmpFile, inet_addr_(*Buffer), @SendData$, StringByteLength(SendData$), #Null, @ReplyBuffer$, StringByteLength(ReplyBuffer$), 1000)
        Result = #True
      EndIf
      FreeMemory(*Buffer)
    EndIf
    IcmpCloseHandle_(hIcmpFile)
  EndIf
  
  ProcedureReturn Result
 
EndProcedure


Debug TestInetConnection("192.168.18.36")
Should work.
Now also with the correct close of the handle :wink:

Bernd

Re: IcmpSendEcho + unicod = not work

Posted: Fri Sep 25, 2015 12:10 pm
by registrymechanic22
infratec wrote:Hi
...
Should work.
Now also with the correct close of the handle :wink:
Bernd
Hi
Very big thank you :D !!
Best regards.

Re: IcmpSendEcho + unicod = not work

Posted: Fri Sep 25, 2015 12:15 pm
by infratec
Found a bug:

one addition of SizeOf(ICMP_ECHO_REPLY) was to much.
Changed the listing above.

Bernd

Re: IcmpSendEcho + unicod = not work

Posted: Fri Sep 25, 2015 1:01 pm
by registrymechanic22
infratec wrote:Found a bug:
one addition of SizeOf(ICMP_ECHO_REPLY) was to much.
Changed the listing above.
Bernd
OK
thank!