Jürgen Meyer
unread,May 19, 2019, 6:03:13 AM5/19/19You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Windows 10 1809 64-bit and Access 2016 32-bit or 64-bit
The following code runs fine on a 32-bit Access, but crashes on 64 bit without
an error message.
I guess, that there is something wrong with my Declares but I can't find the
mistake.
Who sees the problem?
'------------------------------------------------
' Get IPs
'------------------------------------------------
#If Win64 Then
Private Type WSAdata
wVersion As Integer
wHighVersion As Integer
szDescription(0 To 255) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As LongPtr
End Type
Private Type HOSTENT
h_name As LongPtr
h_aliases As LongPtr
h_addrtype As Integer
h_length As Integer
h_addr_list As LongPtr
End Type
Private Type IP_optINFORMATION
TTL As Byte
Tos As Byte
Flags As Byte
OptionsSize As LongPtr
OptionsData As String * 128
End Type
Private Type IP_ECHO_REPLY
Address(0 To 3) As Byte
Status As LongPtr
RoundTripTime As LongPtr
DataSize As Integer
Reserved As Integer
Data As LongPtr
Options As IP_optINFORMATION
End Type
Private Declare PtrSafe Function CopyMemory Lib "kernel32.dll" Alias
"RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
As LongPtr
Private Declare PtrSafe Function GetHostByName Lib "wsock32.dll" Alias
"gethostbyname" (ByVal HostName As String) As LongPtr
Private Declare PtrSafe Function WSAStartup Lib "wsock32.dll" (ByVal
wVersionRequired&, lpWSAdata As WSAdata) As LongPtr
Private Declare PtrSafe Function IcmpCreateFile Lib "icmp.dll" () As LongPtr
Private Declare PtrSafe Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As
LongPtr, ByVal DestAddress As LongPtr, _
ByVal RequestData As String, ByVal RequestSize As Integer, _
RequestOptns As IP_optINFORMATION, ReplyBuffer As IP_ECHO_REPLY, _
ByVal ReplySize As LongPtr, ByVal TimeOut As LongPtr) As Boolean
Dim hHostent As HOSTENT, AddrList As LongPtr
Dim hFile As LongPtr, lpWSAdata As WSAdata
Dim Address As LongPtr, rIP As String
#Else
Private Type WSAdata
wVersion As Integer
wHighVersion As Integer
szDescription(0 To 255) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
Private Type HOSTENT
h_name As Long
h_aliases As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Private Type IP_optINFORMATION
TTL As Byte
Tos As Byte
Flags As Byte
OptionsSize As Long
OptionsData As String * 128
End Type
Private Type IP_ECHO_REPLY
Address(0 To 3) As Byte
Status As Long
RoundTripTime As Long
DataSize As Integer
Reserved As Integer
Data As Long
Options As IP_optINFORMATION
End Type
Private Declare PtrSafe Function CopyMemory Lib "kernel32.dll" Alias
"RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) As
Long
Private Declare PtrSafe Function GetHostByName Lib "wsock32.dll" Alias
"gethostbyname" (ByVal HostName As String) As Long
Private Declare PtrSafe Function WSAStartup Lib "wsock32.dll" (ByVal
wVersionRequired&, lpWSAdata As WSAdata) As Long
Private Declare PtrSafe Function IcmpCreateFile Lib "icmp.dll" () As Long
Private Declare PtrSafe Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As
Long, ByVal DestAddress As Long, _
ByVal RequestData As String, ByVal RequestSize As Integer, _
RequestOptns As IP_optINFORMATION, ReplyBuffer As IP_ECHO_REPLY, _
ByVal ReplySize As Long, ByVal TimeOut As Long) As Boolean
Dim hHostent As HOSTENT, AddrList As Long
Dim hFile As Long, lpWSAdata As WSAdata
Dim Address As Long, rIP As String
#End If
Private Const SOCKET_ERROR = 0
Function Test()
Dim Server As String
Server = "Laptop1"
Call Ping(Server)
End Function
Public Function Ping(ByVal Server As String)
Dim OptInfo As IP_optINFORMATION
Dim EchoReply As IP_ECHO_REPLY
Dim HostName As String
Ping = -1 'Return value set to -1
Server = Replace(Server, "http://", vbNullString)
Server = Replace(Server, "ftp://", vbNullString)
Server = Replace(Server, "/", vbNullString)
If InStr(1, Server, ":") <> 0 Then
Server = Mid$(Server, 1, InStr(1, Server, ":") - 1)
End If
Call WSAStartup(&H101, lpWSAdata)
If GetHostByName(Server + String(64 - Len(Server), 0)) <> SOCKET_ERROR Then
CopyMemory hHostent.h_name, ByVal GetHostByName(Server + String(64 -
Len(Server), 0)), Len(hHostent)
Stop
'In the next two lines Access crashes using 64 bit
CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
CopyMemory Address, ByVal AddrList, 4
End If
hFile = IcmpCreateFile()
If hFile = 0 Then
'Cancel on error
Exit Function
End If
OptInfo.TTL = 255
'Send Ping
If IcmpSendEcho(hFile, Address, String(32, "0"), 32, OptInfo, EchoReply,
Len(EchoReply) + 8, 1000) Then
rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." +
CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3))
If EchoReply.Status = 0 Then Ping = EchoReply.RoundTripTime
End If
End Function
Regards
Juergen