Is there a COM library available to allow URL encoding?

Using VB6. It’s not hard to roll, but I wondered if it was prepared in advance.

+3
source share
2 answers

Tell Bob's comment: Google found this shell for UrlEscape in a press release from Karl Peterson.

Private Declare Function UrlEscape Lib "Shlwapi.dll" Alias "UrlEscapeA" ( _
  ByVal pszURL As String, ByVal pszEscaped As String, ByRef pcchEscaped As Long, _
  ByVal dwFlags As Long) As Long

Private Const URL_DONT_ESCAPE_EXTRA_INFO As Long = &H2000000

Private Function EscapeURL(ByVal URL As String) As String
' Purpose:  A thin wrapper for the URLEscape API function. '
Dim EscTxt As String
Dim nLen As Long

' Create a maximum sized buffer. '
nLen = Len(URL) * 3
EscTxt = Space$(nLen)

If UrlEscape(URL, EscTxt, nLen, URL_DONT_ESCAPE_EXTRA_INFO) = 0 Then
  EscapeURL = Left$(EscTxt, nLen)
End If
End Function

Disclaimer: I have not tried this code myself.

+4
source

You must use CoInternetParseUrl () with URL_ENCODE.

Sample from MSDN, modified for your purposes. Of course, you will have to figure out how to call CoInternetParseUrl () from VB6, but you seem to be on the way to this.

#include <wininet.h>

// ...

WCHAR encoded_url[INTERNET_MAX_URL_LENGTH];
DWORD encoded_url_len = ARRAYSIZE(encoded_url);

// Assumes |url| contains the value you want to encode.

HRESULT hr = CoInternetParseUrl(url, PARSE_CANONICALIZE, URL_ENCODE, encoded_url, 
                        INTERNET_MAX_URL_LENGTH, & encoded_url_len, 0);
if (SUCCEEDED(hr)) {
  // Do stuff...
}

PARSE_ENCODE PARSE_CANONICALIZE, .

, google-url. , ++, COM.

+2

Source: https://habr.com/ru/post/1726999/


All Articles