Re: [VB6] WinHttpCrackUrl
Here you go.. this works :)
Module.bas:
Quote:
Public Declare Function WinHttpCrackUrl _
Lib "winhttp.dll" (ByVal pwszUrl As Long, _
ByVal dwUrlLength As Long, _
ByVal dwFlags As Long, _
ByVal lpUrlComponents As Long) As Long
Public Type URL_COMPONENTS
dwStructSize As Long
lpszScheme As Long
dwSchemeLength As Long
nScheme As Long
lpszHostName As Long
dwHostNameLength As Long
nPort As Long
lpszUserName As Long
dwUserNameLength As Long
lpszPassword As Long
dwPasswordLength As Long
lpszUrlPath As Long
dwUrlPathLength As Long
lpszExtraInfo As Long
dwExtraInfoLength As Long
End Type
Private Declare Function lstrcpyW _
Lib "kernel32.dll" (ByVal lpString1 As Long, _
ByVal lpString2 As Long) As Long
Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long
Public Function StrFromPtr(ByVal lpString As Long) As String
On Error Resume Next
Dim lBuf As Long
lBuf = lstrlenW(lpString)
If (lBuf > 0) Then
StrFromPtr = Space$(lBuf)
Call lstrcpyW(ByVal StrPtr(StrFromPtr), lpString)
End If
End Function
Form / Class:
Quote:
Dim sURL as string, sHost as string
Dim URLCOM As URL_COMPONENTS
sURL = "http://www.google.com/"
With URLCOM
.dwStructSize = Len(URLCOM)
.dwSchemeLength = -1
.dwHostNameLength = -1
.dwUrlPathLength = -1
.dwExtraInfoLength = -1
End With
Call WinHttpCrackUrl(StrPtr(sURL), Len(sURL), &H0, VarPtr(URLCOM))
sHost = StrFromPtr(URLCOM.lpszHostName)
Re: [VB6] WinHttpCrackUrl
Thanks a lot for this. I'd considered the thread dead :)
Do you know if the strings returned from crackurl have to be freed?