-
May 31st, 2017, 02:36 AM
#1
Thread Starter
Junior Member
[RESOLVED] Runtime error - "Bad DLL calling convention" while using UrlEscape API.
I am trying to use the UrlEscape API but I am not sure what mistake I have made in the declaration. I am also not familiar with using pointers in Visual Basic 6.
Code:
Private Declare Function UrlEscape Lib "Shlwapi" Alias "UrlEscapeA" (ByVal pszURL As Long, ByVal pszEscaped As Long, ByRef pcchEscaped As Long, ByVal dwFlags As Long)
Private Const URL_DONT_ESCAPE_EXTRA_INFO = &H2000000
Private Const URL_BROWSER_MODE = &H2000000
Private Const URL_ESCAPE_SPACES_ONLY = &H4000000
Private Const URL_ESCAPE_PERCENT = &H1000
Private Const URL_ESCAPE_SEGMENT_ONLY = &H2000
Private Const URL_ESCAPE_AS_UTF8 = &H40000
Private Const URL_ESCAPE_ASCII_URI_COMPONENT = &H80000
Private Sub Form_Load()
Dim strReturn As String
Dim szSize As Long
Dim strInput As String
strInput = "https://www.google.com/#q=stack+overflow"
szSize = Len(strInput)
Call UrlEscape(StrPtr(strInput), StrPtr(strReturn), szSize, URL_BROWSER_MODE)
MsgBox strReturn
End Sub
-
May 31st, 2017, 03:23 AM
#2
Re: Runtime error - "Bad DLL calling convention" while using UrlEscape API.
Try the sample on the webpage of Randy Birch:
http://vbnet.mvps.org/index.html?cod.../urlescape.htm
It uses the following declaration:
Code:
Private Declare Function UrlEscape Lib "shlwapi" Alias "UrlEscapeA" (ByVal pszURL As String, ByVal pszEscaped As String, pcchEscaped As Long, ByVal dwFlags As Long) As Long
As you can see both the input and the output URLs should be passed as a string.
No StrPtr() needed
-
May 31st, 2017, 03:31 AM
#3
Re: Runtime error - "Bad DLL calling convention" while using UrlEscape API.
See if you have better luck with this:
Code:
Option Explicit
Private Const E_POINTER As Long = &H80004003
Private Const S_OK As Long = 0
Private Const INTERNET_MAX_URL_LENGTH As Long = 2048
Private Const URL_DONT_ESCAPE_EXTRA_INFO = &H2000000
Private Const URL_BROWSER_MODE = &H2000000
Private Const URL_ESCAPE_SPACES_ONLY = &H4000000
Private Const URL_ESCAPE_PERCENT = &H1000
Private Const URL_ESCAPE_SEGMENT_ONLY = &H2000
Private Const URL_ESCAPE_AS_UTF8 = &H40000
Private Const URL_ESCAPE_ASCII_URI_COMPONENT = &H80000
Private Declare Function UrlEscape Lib "Shlwapi" Alias "UrlEscapeW" ( _
ByVal pszURL As Long, _
ByVal pszEscaped As Long, _
ByRef cchEscaped As Long, _
ByVal dwFlags As Long) As Long
Private Sub Form_Load()
Dim strInput As String
Dim cchEscaped As Long
Dim strReturn As String
Dim HRESULT As Long
strInput = "https://www.google.com/#q=stack+overflow"
cchEscaped = (Len(strInput) * 3) \ 2 'Space estimate, cannot be empty.
strReturn = Space$(cchEscaped)
cchEscaped = cchEscaped + 1 'Add terminating NUL.
HRESULT = UrlEscape(StrPtr(strInput), _
StrPtr(strReturn), _
cchEscaped, _
URL_BROWSER_MODE)
If HRESULT = E_POINTER Then
strReturn = Space$(cchEscaped)
cchEscaped = cchEscaped + 1 'Add terminating NUL.
HRESULT = UrlEscape(StrPtr(strInput), _
StrPtr(strReturn), _
cchEscaped, _
URL_BROWSER_MODE)
End If
If HRESULT = S_OK Then
strReturn = Left$(strReturn, cchEscaped)
MsgBox strReturn
Else
MsgBox "UrlEscape error " & Hex$(HRESULT)
End If
End Sub
Don't use it for web scraping. Web scraping is piracy.
You probably want different flags set anyway.
Last edited by dilettante; May 31st, 2017 at 03:34 AM.
-
May 31st, 2017, 04:12 AM
#4
Thread Starter
Junior Member
Re: Runtime error - "Bad DLL calling convention" while using UrlEscape API.
@Arnoutdv @dilettante Thanks! Both the codes are working perfectly.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|