Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1424to1428
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

X64 Declare Function Problem

X64 Declare Function Problem
30.04.2015 21:29:52
Andreas
Hallo zusammen,
ich versuche eine GetHostName Funktion umzusetzen. Leider sind alle Beispiele welche ich gefunden habe für x32. Ich verwende jedoch W64 und Office 64. Kann mal bitte jemand drüberschauen und mir sagen wo ich long zu longptr bzw zu longlong ändern muss?
Danke:
Private Declare PtrSafe Function WSACleanup Lib "WSOCK32" () As Long
Private Declare PtrSafe Function WSAStartup Lib "WSOCK32" (ByVal wVersionRequired As Long, lpWSADATA As WSAData) As Long
Private Declare PtrSafe Function gethostbyaddr Lib "wsock32.dll" (haddr As Long, ByVal hnlen As Long, ByVal addrtype As Long) As Long
Private Declare PtrSafe Function lstrlenA Lib "kernel32" (ByVal Ptr As Any) As Long
Private Declare PtrSafe Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: X64 Declare Function Problem
30.04.2015 22:14:16
Nepumuk
Hallo,
das sollte es sein:
Private Declare PtrSafe Function WSACleanup Lib "wsock32.dll" () As Long
Private Declare PtrSafe Function WSAStartup Lib "wsock32.dll" ( _
    ByVal wVersionRequired As Long, _
    ByRef lpWSADATA As WSAData) As Long
Private Declare PtrSafe Function gethostbyaddr Lib "wsock32.dll" ( _
    ByRef haddr As LongPtr, _
    ByVal hnlen As Long, _
    ByVal addrtype As Long) As LongPtr
Private Declare PtrSafe Function inet_addr Lib "wsock32.dll" ( _
    ByVal cp As String) As LongLong
Private Declare PtrSafe Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
    ByRef Destination As Any, _
    ByRef Source As Any, _
    ByVal Length As LongPtr)
Private Declare PtrSafe Function lstrlen Lib "kernel32" Alias "lstrlenA" ( _
    ByVal lpString As String) As Long

Eventuell musst du die WSAData-Struktur noch anpassen, aber danach hast du ja nicht gefragt.
Gruß
Nepumuk

Anzeige
AW: X64 Declare Function Problem
30.04.2015 22:23:14
Andreas
Hallo Nepumuk,
zunächst herzlichen Dank für Deine Hilfe. Die Declare Aufrufe habe ich nach Deinen Vorgaben geändert. Leider funktioniert es aber immer noch nicht. Da Du bereits bzgl. WSAData Struktur Vermutungen hast erlaube ich mir den kompletten Code zu posten, evtl kannst Du mir ja nochmals helfen:
' ###################################################################################
' ### Constants and Type Definitions
Private Const MIN_SOCKETS_REQD As Long = 1
Private Const WS_VERSION_REQD As Long = &H101
Private Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
Private Const SOCKET_ERROR As Long = -1
Private Const WSADESCRIPTION_LEN = 257
Private Const WSASYS_STATUS_LEN = 129
Private Const MAX_WSADescription = 256
Private Const MAX_WSASYSStatus = 128
Private Type WSAData
wVersion As Integer
wHighVersion As Integer
szDescription(0 To MAX_WSADescription) As Byte
szSystemStatus(0 To MAX_WSASYSStatus) As Byte
wMaxSockets As Integer
wMaxUDPDG As Integer
dwVendorInfo As Long
End Type
' ### WINSOCK Native Function Imports
Private Declare PtrSafe Function WSACleanup Lib "wsock32.dll" () As Long
Private Declare PtrSafe Function WSAStartup Lib "wsock32.dll" ( _
ByVal wVersionRequired As Long, _
ByRef lpWSADATA As WSAData) As Long
Private Declare PtrSafe Function gethostbyaddr Lib "wsock32.dll" ( _
ByRef haddr As LongPtr, _
ByVal hnlen As Long, _
ByVal addrtype As Long) As LongPtr
Private Declare PtrSafe Function inet_addr Lib "wsock32.dll" ( _
ByVal cp As String) As LongLong
Private Declare PtrSafe Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
ByRef Destination As Any, _
ByRef Source As Any, _
ByVal Length As LongPtr)
Private Declare PtrSafe Function lstrlen Lib "kernel32" Alias "lstrlenA" ( _
ByVal lpString As String) As Long
' ### Private Utility Functions
Private Function HiByte(ByVal wParam As Integer)
HiByte = wParam \ &H100 And &HFF&
End Function
Private Function LoByte(ByVal wParam As Integer)
LoByte = wParam And &HFF&
End Function
Private Sub SocketsCleanup()
If WSACleanup()  ERROR_SUCCESS Then
MsgBox "Socket error occurred in Cleanup."
End If
End Sub
Private Function SocketsInitialize() As Boolean
Dim WSAD As WSAData
Dim sLoByte As String
Dim sHiByte As String
If WSAStartup(WS_VERSION_REQD, WSAD)  ERROR_SUCCESS Then
MsgBox "The 32-bit Windows Socket is not responding."
SocketsInitialize = False
Exit Function
End If
If WSAD.wMaxSockets  0 Then
CopyMemory lRet, ByVal lRet, 4
lLength = lstrlenA(lRet)
If lLength > 0 Then
GetHostName = Space$(lLength)
CopyMemory ByVal GetHostName, ByVal lRet, lLength
End If
Else
GetHostName = ""
End If
SocketsCleanup
End Function
Der Fehler tritt in der 13 Zeile von unten auf:
lRet = gethostbyaddr(inet_addr(Address), 4, AF_INET)
--> Typen unverträglich
Besten Dank
LG

Anzeige
AW: X64 Declare Function Problem
30.04.2015 22:50:36
Nepumuk
Hallo,
teste mal:
Private Type WSAData
    wVersion As Long
    wHighVersion As Long
    szDescription(0 To MAX_WSADescription) As Byte
    szSystemStatus(0 To MAX_WSASYSStatus) As Byte
    wMaxSockets As Integer
    wMaxUDPDG As Integer
    dwVendorInfo As LongPtr
End Type

Gruß
Nepumuk

Anzeige
AW: X64 Declare Function Problem
30.04.2015 22:55:53
Andreas
Leider hat sich nichts geändert, noch immer selber Fehler...
LG

AW: X64 Declare Function Problem
30.04.2015 23:00:23
Nepumuk
Hallo,
wie ich gerade gelesen habe, hat Microsoft in der 64Bit-Version Parameter vertauscht. Ich hoffe jetzt passt es denn sonst fällt mir auch nichts ein:
Private Type WSAData
    wVersion As Long
    wHighVersion As Long
    wMaxSockets As Integer
    wMaxUDPDG As Integer
    dwVendorInfo As LongPtr
    szDescription(0 To MAX_WSADescription) As Byte
    szSystemStatus(0 To MAX_WSASYSStatus) As Byte
End Type

Gruß
Nepumuk

Anzeige
AW: X64 Declare Function Problem
30.04.2015 23:05:31
Andreas
Leider noch immer keine Änderung. Trotzdem nochmlas vielen Dank für Deine Mühen. Falls noch wer eine Idee hat, immer gerne :-)
LG

AW: X64 Declare Function Problem
01.05.2015 09:34:49
Nepumuk
Hallo,
hast du schon versucht die Fehlermeldung der DLL anzuzeigen? So nach dem Muster:
Option Explicit

Private Declare PtrSafe Function FormatMessageA Lib "kernel32.dll" ( _
    ByVal dwFlags As Long, _
    ByRef lpSource As Any, _
    ByVal dwMessageId As Long, _
    ByVal dwLanguageId As Long, _
    ByVal lpBuffer As String, _
    ByVal nSize As Long, _
    ByRef Arguments As LongPtr) As Long
Private Declare PtrSafe Function GetLastError Lib "kernel32.dll" () As Long

Private Const LANG_NEUTRAL As Long = &H0
Private Const ERROR_BUFFER As Long = &HC8
Private Const FORMAT_MESSAGE_FROM_SYSTEM As Long = &H1000

Sub test()
    
    Dim strBuffer As String
    strBuffer = Space$(ERROR_BUFFER)
    Call FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, GetLastError, _
        LANG_NEUTRAL, strBuffer, ERROR_BUFFER, ByVal CLngPtr(0))
    MsgBox strBuffer
    
End Sub

Du liest den Rückgabewert der DLL und wenn der z.B. 0 zurück gibt dann den Fehler auslesen. Google mal nach den Namen der Funktion und schau in der MSDN-Library nach was die Funktion für Rückgabewerte haben kann.
Gruß
Nepumuk
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige