Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Has anybody successfully used InternetCrackUrl (WinInet function) ?

498 views
Skip to first unread message

Priya

unread,
Sep 24, 1998, 3:00:00 AM9/24/98
to
I'm trying to use the InternetCrackUrl WinInet API from VB , but the function is returning
error 87 (Invalid Parameter). has anybody successfully used this function from VB .
I'm not sure if the declarations that I've converted to VB are correct .
I'd appreciate any suggestion.

Here's the code I'm using :
'===============================
'Declarations
'===============================
Public Type URL_COMPONENTS
structSize As Long
strScheme As String
lenStrScheme As Long
nScheme As Long
strHostName As String
lenstrHostName As Long
nPort As Integer
strUserName As String
lenstrUserName As Long
strPassword As String
lenstrPassword As Long
strURLPath As String
lenURLPath As Long
strExtraInfo As String
lenstrExtra As Long
End Type

Public Const ICU_DECODE = &H10000000 ' Convert %XX escape sequences to characters
Public Const ICU_ESCAPE = &H80000000 ' (un)escape URL characters

Public Declare Function InternetCrackUrl Lib "wininet.dll" Alias "InternetCrackUrlA" _
(ByVal lpURL As String, ByVal lpURLLength As Long, ByVal lpFlags As Long, _
lpURLComponents As URL_COMPONENTS) As Long

'===============================
code
'===============================
Dim ret As Long
Dim urlcomp As URL_COMPONENTS
Dim strURL As String
Dim buffer As String
buffer = Space$(255)
strURL = "http:%2F%2Fwww.microsoft.com%2Findex.htm"

urlcomp.structSize = Len(urlcomp)
urlcomp.lenURLPath = 255
urlcomp.lenstrExtra = 255
urlcomp.lenstrHostName = 255
urlcomp.lenstrPassword = 255
urlcomp.lenStrScheme = 255
urlcomp.lenstrUserName = 255

urlcomp.strURLPath = buffer
ret = InternetCrackUrl(strURL, Len(strURL), ICU_DECODE, urlcomp)


Thanks for your time.
Regards,
Priya
Trisoft Design
E 30 Connaught Place
New Delhi 110 001 India
email: priyam@ trisoftdesign.com
http://www.trisoftdesign.com
Tel: 335 3885, 372 5407, 373 8651, 373 8653
Fax: 91 11 335 4959

Karl E. Peterson

unread,
Sep 24, 1998, 3:00:00 AM9/24/98
to
One thing I noticed is that you weren't preassigning the return buffers. Could be
other stuff too, so rather than pick it apart, here's what I've used...

Private Declare Function InternetCrackUrl Lib "wininet.dll" Alias
"InternetCrackUrlA" (ByVal lpszUrl As String, ByVal dwUrlLength As Long, ByVal
dwFlags As Long, lpUrlComponents As URL_COMPONENTS) As Long
Private Declare Function InternetCanonicalizeUrl Lib "wininet.dll" Alias
"InternetCanonicalizeUrlA" (ByVal lpszUrl As String, ByVal lpszBuffer As String,
lpdwBufferLength As Long, ByVal dwFlags As Long) As Long
Private Declare Function InternetCreateUrl Lib "wininet.dll" Alias
"InternetCreateUrlA" (lpUrlComponents As URL_COMPONENTS, ByVal dwFlags As Long, ByVal
lpszUrl As String, lpdwUrlLength As Long) As Long

Private Type URL_COMPONENTS 'typedef struct {
StructSize As Long ' DWORD dwStructSize;
Scheme As String ' LPSTR lpszScheme;
SchemeLength As Long ' DWORD dwSchemeLength;
nScheme As Long ' INTERNET_SCHEME nScheme;
HostName As String ' LPSTR lpszHostName;
HostNameLength As Long ' DWORD dwHostNameLength;
nPort As Long ' INTERNET_PORT nPort;
UserName As String ' LPSTR lpszUserName;
UserNameLength As Long ' DWORD dwUserNameLength;
Password As String ' LPSTR lpszPassword;
PasswordLength As Long ' DWORD dwPasswordLength;
URLPath As String ' LPSTR lpszUrlPath;
UrlPathLength As Long ' DWORD dwUrlPathLength;
ExtraInfo As String ' LPSTR lpszExtraInfo;
ExtraInfoLength As Long ' DWORD dwExtraInfoLength;
End Type '} URL_COMPONENTS;
'//
'// flags for InternetCrackUrl() and InternetCreateUrl()
'//
Private Const ICU_ESCAPE = &H80000000 '// (un)escape URL characters
Private Const ICU_USERNAME = &H40000000 '// use internal username &
password
'//
'// flags for InternetCanonicalizeUrl() and InternetCombineUrl()
'//
Private Const ICU_NO_ENCODE = &H20000000 '// Don't convert unsafe characters to
escape sequence
Private Const ICU_DECODE = &H10000000 '// Convert %XX escape sequences to
characters
Private Const ICU_NO_META = &H8000000 '// Don't convert .. etc. meta path
sequences
Private Const ICU_ENCODE_SPACES_ONLY = &H4000000 '// Encode spaces only
Private Const ICU_BROWSER_MODE = &H2000000 '// Special encode/decode rules for
browser


Public Function CrackUrl(ByVal URL As String, cmp As URL_COMPONENTS) As Boolean
Dim Buffer As String
Dim BufLen As Long
Const BufSize = 1024
'
' Try to insure a valid URL to begin with
'
Buffer = Space$(BufSize)
BufLen = Len(Buffer)
If InternetCanonicalizeUrl(URL, Buffer, BufLen, ICU_BROWSER_MODE) Then
URL = Left(Buffer, BufLen)
'
' Reset structure and supply buffers
'
With cmp
.StructSize = Len(cmp)
.Scheme = Space$(BufSize)
.SchemeLength = BufSize
.nScheme = InternetSchemeUnknown
.HostName = Space$(BufSize)
.HostNameLength = BufSize
.nPort = 0
.UserName = Space$(BufSize)
.UserNameLength = BufSize
.Password = Space$(BufSize)
.PasswordLength = BufSize
.URLPath = Space$(BufSize)
.UrlPathLength = BufSize
.ExtraInfo = Space$(BufSize)
.ExtraInfoLength = BufSize
End With
'
' Crack URL apart and get what we can from it
'
CrackUrl = CBool(InternetCrackUrl(URL, Len(URL), ICU_ESCAPE, cmp))
'
' Clean up structure to get rid of crapola
'
With cmp
.Scheme = TrimNull(.Scheme)
.HostName = TrimNull(.HostName)
.UserName = TrimNull(.UserName)
.Password = TrimNull(.Password)
.URLPath = TrimNull(.URLPath)
.ExtraInfo = TrimNull(.ExtraInfo)
End With
Else
CrackUrl = False
'Debug.Print Err.LastDllError, ApiErrorText(Err.LastDllError)
End If
End Function

Later... Karl
--
[This space intentionally left blank.]


Priya wrote in message <360A2736...@trisoftdesign.com>...

Priya

unread,
Sep 25, 1998, 3:00:00 AM9/25/98
to
Thanks a heap Karl.
0 new messages