Results 1 to 3 of 3

Thread: [VB6] WinHttpCrackUrl

  1. #1

    Thread Starter
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    [VB6] WinHttpCrackUrl

    Does anyone have a working example of using WinHttpCrackUrl? For some reason I can't get this one working for the life of me. Here's the declarations I have so far.

    Code:
    Private Declare Function WinHttpCrackUrl Lib "WinHTTP.DLL" ( _
            ByVal pwszUrl As Long _
            , ByVal dwUrlLength As Long _
            , ByVal dwFlags As Long _
            , ByRef lpUrlComponents As URL_COMPONENTS _
            ) As Long                                ' BOOL
    Code:
    Type URL_COMPONENTS
        dwStructSize As Long                         ' DWORD // size of this structure. Used in version check
        lpszScheme As Long                           ' LPSTR // pointer to scheme name
        dwSchemeLength As Long                       ' DWORD // length of scheme name
        nScheme As Long                              ' INTERNET_SCHEME // enumerated scheme type (if known)
        lpszHostName As Long                         ' LPSTR // pointer to host name
        dwHostNameLength As Long                     ' DWORD // length of host name
        nPort As Long                                ' INTERNET_PORT // converted port number
        lpszUserName As Long                         ' LPSTR // pointer to user name
        dwUserNameLength As Long                     ' DWORD // length of user name
        lpszPassword As Long                         ' LPSTR // pointer to password
        dwPasswordLength As Long                     ' DWORD // length of password
        lpszUrlPath As Long                          ' LPSTR // pointer to URL-path
        dwUrlPathLength As Long                      ' DWORD // length of URL-path
        lpszExtraInfo As Long                        ' LPSTR // pointer to extra information (e.g. ?foo or #foo) (Z string)
        dwExtraInfoLength As Long                    ' DWORD // length of extra information
    End Type
    Last edited by dmaruca; May 6th, 2011 at 03:33 PM.

  2. #2
    New Member
    Join Date
    Dec 2007
    Posts
    6

    Re: [VB6] WinHttpCrackUrl

    Here you go.. this works


    Module.bas:
    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:
    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)

  3. #3

    Thread Starter
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width