Attribute VB_Name = "mEncode" Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2006 VBnet, Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Const MAX_PATH As Long = 260 Private Const ERROR_SUCCESS As Long = 0 'Treat entire URL param as one URL segment Private Const URL_ESCAPE_SEGMENT_ONLY As Long = &H2000 Private Const URL_ESCAPE_PERCENT As Long = &H1000 Private Const URL_UNESCAPE_INPLACE As Long = &H100000 'escape #'s in paths Private Const URL_INTERNAL_PATH As Long = &H800000 Private Const URL_DONT_ESCAPE_EXTRA_INFO As Long = &H2000000 Private Const URL_ESCAPE_SPACES_ONLY As Long = &H4000000 Private Const URL_DONT_SIMPLIFY As Long = &H8000000 'Converts unsafe characters, 'such as spaces, into their 'corresponding escape sequences. 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 'Converts escape sequences back into 'ordinary characters. Private Declare Function UrlUnescape Lib "shlwapi" _ Alias "UrlUnescapeA" _ (ByVal pszURL As String, _ ByVal pszUnescaped As String, _ pcchUnescaped As Long, _ ByVal dwFlags As Long) As Long Public Function EncodeUrl(ByVal sUrl As String) As String Dim buff As String Dim dwSize As Long Dim dwFlags As Long If Len(sUrl) > 0 Then buff = Space$(MAX_PATH) dwSize = Len(buff) dwFlags = URL_DONT_SIMPLIFY If UrlEscape(sUrl, _ buff, _ dwSize, _ dwFlags) = ERROR_SUCCESS Then EncodeUrl = Left$(buff, dwSize) End If 'UrlEscape End If 'Len(sUrl) End Function