August 11, 2001

Winsock Programming

Most of you might have worked withInternet Transfer Control which is very handy control when it comes to InternetProgramming but there is another control which even more robust and helpsprogrammers creating more flexible applications. Winsock control comes with VB6and is used to create applications that access the low-level functions of

SetIEStartPage – Change IE start page

‘ Set the IE start page’ Note: requires the SetRegistryValue, CheckRegistryKey and CreateRegistryKey ‘ routines, you can find them in the CodeBank’ Example:’ SetIEStartPage “http://www.vb2themax.com”Public Sub SetIEStartPage(ByVal sPage As String) Const HKEY_CURRENT_USER = &H80000001 Dim sKey As String sKey = “SoftwareMicrosoftInternet ExplorerMain” ‘ if the Key does not exist If

URLEncodeEx – Apply URL encoding rules

‘ Applies URL encoding rules to the specified Text and returns the result’ (similar to Server.URLEncode)Public Function URLEncodeEx(ByVal Text As String) As String Dim abytTokens() As Byte Dim lngTotal As Long Dim lngCount As Long Dim astrReturn() As String Dim strReturn As String strReturn = Text If Trim$(strReturn) “” Then

URLDecodeEx – Decodes an encoded URL

‘ Decodes URL encoding applied to the specified Text and returns the resultPublic Function URLDecodeEx(ByVal Text As String) As String Dim abytTokens() As Byte Dim lngTotal As Long Dim lngCount As Long Dim astrReturn() As String Dim strReturn As String Dim strHex As String Dim strDec As String strReturn =

HTMLEncodeEx – Applies HTML encoding rules to the specified Text

‘ Applies HTML encoding rules to the specified Text and returns the result” Optionally specify if we’re encoding a HREF link and the character’ to use for encoding – the default is the standard ampersand’ e.g. Server.HTMLEncode’ i.e. Call MsgBox(HTMLEncodeEx(“”)) Public Function HTMLEncodeEx(ByVal Text As String, Optional ByVal vfHREFEncode _

GetIEStartPage – Read IE start page

‘ Get the IE start page’ Note: requires the GetRegistryValue routine, you can find it in the CodeBank’ Example:’ MsgBox GetIEStartPagePublic Function GetIEStartPage() As String Const HKEY_CURRENT_USER = &H80000001 GetIEStartPage = GetRegistryValue(HKEY_CURRENT_USER, _ “SoftwareMicrosoftInternet ExplorerMain”, “Start Page”)End Function

HTMLDecodeEx – Decodes HTML encoded strings

‘ Decodes HTML encoding applied to the specified Text and returns the result’ Optionally specify if we encoded a HREF link and the character’ used for encoding – the default is the standard ampersand’ i.e. Call MsgBox(HTMLDecodeEx(“<Sample HTML Decoded Text>”‘ & “”))Public Function HTMLDecodeEx(ByVal Text As String, Optional ByVal vfHREFDecode _ As Boolean