Probleme mit Umsetzung auf 64 Bit
28.02.2017 21:25:36
Thorsten
ich habe vor einiger Zeit ein umfangreiches Tool unter Excel 2007 (32 Bit) in VBA entwickelt, u.a. mit FTP-Zugriffen. Den Code für die FTP-Funktionalität habe ich damals hier 1:1 entnommen:
http://www.office-loesung.de/ftopic154081_0_0_asc.php
Funktionierte bisher alles bestens. Vor ein paar Tagen habe ich auf meinem PC Excel 2013 (64 _ Bit) installiert und habe mit Erschrecken festgestellt, dass das Tool unter 64 Bit nicht läuft! Ich beschäftige mich jetzt schon seit einigen Tagen intensiv mit dem Problem, aber lösen konnte ich es noch nicht. Ich habe allen "Declare" ein PtrSafe hinzugefügt und alle Handles und Zeiger vom Typ Long in LongPtr konvertiert. Excel beendet sich immer in folgender Funktion beim Aufruf von
MoveMemory IPArray(0), ByVal pIP, 4
(--> Excel funktioniert nicht mehr...):Private Function IPAdresse(ByVal Adresse As String) As String
Dim pAdresse As LongPtr, AdresseInfo As HOSTENT
Dim pIP As LongPtr, IPArray(3) As Byte
Dim WSADaten As WSAData
WSAStartup &H202, WSADaten
pAdresse = gethostbyname(Adresse)
If pAdresse = 0 Then
IPAdresse = 0
Exit Function
End If
MoveMemory AdresseInfo, ByVal pAdresse, Len(AdresseInfo)
MoveMemory pIP, ByVal AdresseInfo.haddrlist, 4
MoveMemory IPArray(0), ByVal pIP, 4
WSACleanup
IPAdresse = IPArray(0) & "." & IPArray(1) & "." & IPArray(2) & "." & IPArray(3)
End Function
Ich weiß keinen Rat mehr :(. Ich hoffe dass mir hier irgendjemand helfen kann, bin dankbar für jeden Hinweis! Danke schon mal im Voraus!
VG
Thorsten
_________________________________________
Hier noch der Ausschnitt des Codes, der von mir bearbeitet wurde:
Option Explicit
Private Declare PtrSafe Function WSACleanup Lib "ws2_32.dll" () As Long
Private Declare PtrSafe Function WSAStartup Lib "ws2_32.dll" (ByVal wVersionRequired As Integer, _
ByRef lpWSAData As WSAData) As Long
Private Declare PtrSafe Function socket Lib "ws2_32.dll" (ByVal af As Long, ByVal lType As Long, _
ByVal protocol As Long) As Long
Private Declare PtrSafe Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef _
Destination As Any, ByRef Source As Any, ByVal length As Long)
Private Declare PtrSafe Function gethostbyname Lib "wsock32.dll" (ByVal name As String) As _
LongPtr
Private Declare PtrSafe Function closesocket Lib "ws2_32.dll" (ByVal s As Long) As Long
Private Declare PtrSafe Function recv Lib "ws2_32.dll" (ByVal s As Long, ByVal buf As String, _
ByVal lLen As Long, ByVal flags As Long) As Long
Private Declare PtrSafe Function send Lib "ws2_32.dll" (ByVal s As Long, ByVal buf As String, _
ByVal lLen As Long, ByVal flags As Long) As Long
Private Declare PtrSafe Function connect Lib "ws2_32.dll" (ByVal s As Long, ByRef name As _
SOCKADDR, ByVal namelen As Long) As Long
Private Declare PtrSafe Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As LongLong
Private Declare PtrSafe Function htons Lib "wsock32.dll" (ByVal hostshort As Integer) As _
Integer
Private Declare PtrSafe Function ioctlsocket Lib "wsock32.dll" (ByVal s As Long, ByVal cmd As _
Long, argp As LongPtr) As Long
Private Declare PtrSafe Function KillTimer Lib "user32.dll" (ByVal hWnd As LongPtr, ByVal _
nIDEvent As LongPtr) As Long
Private Declare PtrSafe Function SetTimer Lib "user32.dll" (ByVal hWnd As LongPtr, ByVal _
nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Private Type DateiAuslesenResult
result() As Byte
End Type
Private Type WSAData
wVersion As Integer
wHighVersion As Integer
szDescription As String * 257
szSystemStatus As String * 129
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As LongPtr
End Type
Private Type SOCKADDR
sin_family As Integer
sin_port As Integer
sin_addr As LongPtr
sin_zero As String * 8
End Type
Private Type HOSTENT
hname As Long
haliases As Long
haddrtype As Integer
hlength As Integer
haddrlist As Long
End Type
Type Benutzerrechte
Eigentümer As Dateirechte
Gruppe As Dateirechte
sonstige As Dateirechte
End Type
Private Enum Dateirechte
lesen = 4
schreiben = 2
Ausführen = 1
End Enum
Private Const AF_INET = 2
Private Const SOCK_STREAM = 1
Private Const MSG_PEEK = &H2
Private Const FIONBIO = &H8004667E
Private aSocket As Long
Private aHost As String
Private Timer As LongPtr
Private ret As Variant
Public FTPerror As Boolean
Private Function IPAdresse(ByVal Adresse As String) As String
Dim pAdresse As LongPtr, AdresseInfo As HOSTENT
Dim pIP As LongPtr, IPArray(3) As Byte
Dim WSADaten As WSAData
WSAStartup &H202, WSADaten
pAdresse = gethostbyname(Adresse)
If pAdresse = 0 Then
IPAdresse = 0
Exit Function
End If
MoveMemory AdresseInfo, ByVal pAdresse, Len(AdresseInfo)
MoveMemory pIP, ByVal AdresseInfo.haddrlist, 4
MoveMemory IPArray(0), ByVal pIP, 4
WSACleanup
IPAdresse = IPArray(0) & "." & IPArray(1) & "." & IPArray(2) & "." & IPArray(3)
End Function
Private Function Verbinden(ByVal Adresse As String, ByVal Port As Long) As Long
Dim result
Dim SockAdresse As SOCKADDR
Dim intPort As Integer
Select Case Port
Case Is 0 Then
Verbinden = False
Exit Function
End If
result = ioctlsocket(Verbinden, FIONBIO, 1&)
If result = -1 Then
Verbinden = False
Exit Function
End If
End Function
Private Function VerbindungTrennen(ByVal s As Long)
closesocket s
s = 0
End Function
(...)