Your Ad Here

Wednesday, December 30, 2009

Winsock Proxy

Tools:

1) Visual Basic
2) Winsock Control
3) Working proxy server

Why use proxies ?

It is very useful if you are making a website flooder / attacking tool. I've seen plenty of programs that connect directly to the target site. It's probably the dumbest thing you can do. It'd be a simple matter for the web host or even the webmaster of the target site to find your IP address.

Let's get started.

Open Visual Basic and add Winsock Control , Command button and 2 text boxes to your form.

Rename Controls:

-Winsock = wskProxy

-TextBox2 = txtPort

-TextBox1 = txtServer

-Command Button = cmdConnect

The code.

To txtServer you add the proxy server and to txtPort you add the proxy's port number.

Private Sub cmdConnect_Click()

With wskProxy
.Close ' We close our socket. Just incase
.Connect txtServer.Text, txtPort.Text ' This connects to proxy server
End With

End Sub


_______________________________________________________________________

Note: This is just an example of a simple GET function.
The best tool that lets you see GET / POST headers is a packet watcher.
I recommend using a SocSpy or Commview.
_______________________________________________________________________


Private Sub
wskProxy_Connect()
Dim
ThePage As String, TheHost As String

ThePage = "" ' Here we usually put something like this. Ex: "programs/vb/program.zip"
' Basically it's a file that we are requesting.

TheHost = "www.whatismyip.com" ' Now this is the host, that's where the file is.

' And here comes the HTML header

With
wskProxy
.SendData "GET /" & ThePage & " HTTP/1.1" & vbCrLf
.SendData "Accept: text/plain" & vbCrLf
.SendData "Accept-Language: en-us" & vbCrLf
.SendData "Accept-Encoding: gzip, deflate" & vbCrLf
.SendData "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & vbCrLf
.SendData "Host: " & TheHost & vbCrLf
.SendData "Connection: Keep-Alive" & vbCrLf & vbCrLf
End With


End Sub
_______________________________________________________________________

' This Sub is not that important unless you need to see the incoming data

Private Sub wskProxy_DataArrival(ByVal bytesTotal As Long)
Dim strData As String

wskProxy.PeekData strData, vbString, bytesTotal

End Sub

_______________________________________________________________________

data coming in is chunke

I wrote an application in vb 6.0. Very simple using the winsock control. Everything works fine.. Except certain things.

One of the problems is that my winsock data coming in is chunked. At first I used an example like this:

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
Winsock1.GetData Data
text1 = Data
End If

Then I would get sporadic text with a few characters only appearing.

Then I tried:

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
Winsock1.GetData Data
text1 = text1 & Data
End If

Which seems to collect all the data, but there are many carriage returns & blocks in the text. I would like to be able to collect the whole dataarrival & Display it entirely & clearly to perform a regex.

The regex I need to scan the dataarrival with is:

Delimiter or special characters = "/?"

And after that, perform this regex:

regex.Pattern = "<a href=x22[^>]*x22 href=([^>]*)>(.*?)</a>"

I can explain more as I am trying to extract certain hyperlinks from the winsock dataarrival.

Internet Transfer Control

Most of you might have worked with Internet Transfer Control which is very handy control when it comes to Internet Programming but there is another control which even more robust and helps programmers creating more flexible applications. Winsock control comes with VB6 and is used to create applications that access the low-level functions of the Transmission Control Protocol/Internet Protocol (TCP/IP).



TCP/IP is a specification that defines a series of protocols used to standardize how computers exchange information with each other. TCP/IP provides communication across interconnected networks that use diverse hardware architectures and various operating systems. The protocols in TCP/IP are arranged in a series of layers known as a protocol stack. Each layer has its own functionality.

Winsock is a standard that is maintained by Microsoft. This standard is basically a set of routines that describe communications to and from the TCP/IP stack. These routines reside in a dynamic link library that runs under Windows. The winsock DLL is interfaced with TCP/IP and from there through the Internet.

In this article, I am going to show how to use the winsock in a client server environment, we will create two separate applications, one of which will be a server and the other will be a client. Both client and server will interact with each other to exchange data. Client will send a request to the server and the server which will be connected to a database will retrieve the information requested by the client from the database and will return the requested information back to the client. You will a database with this article, the database contains the item numbers and their prices. In real life situations, database might be located on a machine different from the one that hosts the client application.

I think it would be better to talk about the ports before we proceed any further. A port is a special memory location that exists when two computers are in communication via TCP/IP. Applications use a port number as an identifier to other computers, both the sending and receiving computers use this port to exchange data.

To make the job of communication easier, some port numbers have been standardized. These standard port numbers have no inherent value other than that users have agreed to use them with certain applications. Table below lists a number of popular and publicly accepted port numbers and their corresponding applications.

Service

Port

HTTP

80

FTP

20,21

Gopher

70

SMTP

25

POP3

110

Telnet

23

Finger

79

Local loops/callbacks

0

Using the Winsock Control

Winsock is above the TCP/IP protocol stack in the ISO/OSI model. TCP/IP is an industry standard communication protocol that defines methods for packaging data into packets for transmission between computing devices on a heterogeneous network. TCP/IP is the standard for data transmission over networks, including the Internet. TCP establishes a connection for data transmission and IP defines the method for sending data packets.

The Microsoft Winsock control makes using the TCP/IP a breeze. Microsoft has wrapped up the Winsock and INetAPI API calls into a nice neat package that you can easily incorporate into your Visual Basic applications.

Winsock Operating Modes

The Transport layer (also known as the Host-to-Host Transport layer) is responsible for providing the Application layer with session and datagram communication services. The core protocols of the Transport layer are TCP and User Datagram Protocol (UDP). The Winsock control supports the following two operating modes:

  • sckTCPProtocol
  • sckUDPProtocol

Winsock Properties

Winsock enables you to create clients and servers using the same control. This dual functionality enables you to specify through property setting the type of application you will be building. The Winsock control uses a number of the same properties, whether you are creating client or a server, thereby all but eliminating the learning curve needed to create applications. Some of the important properties of the control are as following:

BytesReceived Property

This property returns the number of bytes currently in the receive buffer. This is a read-only property and is unavailable at design time. The value returned is a long integer.

LocalHostName Property

The LocalHostName property returns the name of the local host system. This is read-only property and is unavailable at the design time. The value returned is a string.

LocalIP Property

The LocalIP property returns the local host system IP address in the form of a string, such as 11.0.0.127. This property is read-only and is unavailable at design time.

LocalPort Property

This property returns or sets the local port number. This can be both read from and written to and is available at both design time and runtime. The value returned is a long integer.

Protocol Property

Returns or sets the protocol, either TCP or UDP, used by the Winsock control.

RemoteHost Property

The RemoteHost property returns or sets the remote host. This can be both read from and written to and is available both in design time and runtime. The value returned is a string and can be specified either as an IP address or as a DNS name.

RemotePort Property

This property returns or sets the remote port number.

State Property

This returns the state of the control as expressed by an enumerated list. This is read-only property and is unavailable at design time.

Some of the important methods of Winsock control are as following:


Using the Winsock Control in Client/Server Applications

The Internet Transfer Control (ITC) is a handy control for Internet programming, but there is another control that is even more robust and helps programmers to create more flexible applications. The Winsock control comes with Visual Basic 6.0 (VB6) and is used to create applications that access the low-level functions of the Transmission Control Protocol/Internet Protocol (TCP/IP).

TCP/IP is a specification that defines a series of protocols used to standardize how computers exchange information with each other. TCP/IP provides communication across interconnected networks that use diverse hardware architectures and various operating systems. The protocols in TCP/IP are arranged in a series of layers known as a protocol stack. Each layer has its own functionality.

Winsock is a standard that is maintained by Microsoft. This standard is basically a set of routines that describe communications to and from the TCP/IP stack. These routines reside in a dynamic link library (DLL) that runs under Windows. The Winsock DLL is interfaced with TCP/IP and from there through the Internet.

This article will show how to use the Winsock in a client server environment. We will create two separate applications, one of which will be a server and the other will be a client. Both client and server will interact with each other to exchange data. Client will send a request to the server, and the server, which will be connected to a database, will retrieve the information requested by the client from the database and will return the requested information back to the client. You will find a database with this article. The database contains item numbers and their prices. In real-life situations, the database might be located on a machine different from the one that hosts the client application.

Ports
Let's talk about the ports before we proceed any further. A port is a special memory location that exists when two computers are in communication via TCP/IP. Applications use a port number as an identifier to other computers. Both the sending and receiving computers use this port to exchange data.

To make the job of communication easier, some port numbers have been standardized. These standard port numbers have no inherent value other than that users have agreed to use them with certain applications. The table below lists a number of popular and publicly accepted port numbers and their corresponding applications.

ServicePort
HTTP 80
FTP 20, 21
Gopher 70
SMTP 25
POP3 110
Telnet 23
Finger 79
Local loops/callbacks 0

  • download supporting source code
  • Using the Winsock Control

    Winsock is above the TCP/IP protocol stack in the ISO/OSI model. TCP/IP is an industry standard communication protocol that defines methods for packaging data into packets for transmission between computing devices on a heterogeneous network. TCP/IP is the standard for data transmission over networks, including the Internet. TCP establishes a connection for data transmission and IP defines the method for sending data packets.

    The Microsoft Winsock control makes using the TCP/IP a breeze. Microsoft has wrapped up the Winsock and NETAPI API calls into a neat package that you can easily incorporate into your Visual Basic applications.

    Winsock Operating Modes

    The Transport layer (also known as the Host-to-Host Transport layer) is responsible for providing the Application layer with session and datagram communication services. The core protocols of the Transport layer are TCP and User Datagram Protocol (UDP). The Winsock control supports the following two operating modes:

    • sckTCPProtocol
    • sckUDPProtocol

    Winsock Properties

    Winsock enables you to create clients and servers using the same control. This dual functionality enables you to specify through property setting the type of application you will be building. The Winsock control uses a number of the same properties, whether you are creating a client or a server, thereby all but eliminating the learning curve needed to create applications. Some of the important properties of the control are as follows:

    BytesReceived Property

    This property returns the number of bytes currently in the receive buffer. This is a read-only property and is unavailable at design time. The value returned is a long integer.

    LocalHostName Property

    The LocalHostName property returns the name of the local host system. This is a read-only property and is unavailable at design time. The value returned is a string.

    LocalIP Property

    The LocalIP property returns the local host system IP address in the form of a string, such as 11.0.0.127. This property is read-only and is unavailable at design time.

    LocalPort Property

    This property returns or sets the local port number. This can be both "read from" and "written to" and is available at both design time and runtime. The value returned is a long integer.

    Protocol Property

    Returns or sets the protocol, either TCP or UDP, used by the Winsock control.

    RemoteHost Property

    The RemoteHost property returns or sets the remote host. This can be both "read from" and "written to" and is available both in design time and runtime. The value returned is a string and can be specified either as an IP address or as a DNS name.

    RemotePort Property

    This property returns or sets the remote port number.

    State Property

    This returns the state of the control as expressed by an enumerated list. This is a read-only property and is unavailable at design time.

    Winsock Methods

    Some of the important methods of Winsock control are as follows:

    Accept Method

    It accepts the request for connection from the client system. For this method to be used, the control must be in the listening state.

    Close Method

    The Close method terminates a TCP connection from either the client or server applications.

    GetData Method

    GetData is the method that retrieves the current block of data from the buffer and then stores it in a variable of the variant type.

    PeekData Method

    The PeekData method operates in a fashion similar to the GetData method. However, it does not remove data from the input queue.

    Listen Method

    This is invoked on the server application to have the server application wait for a TCP request for connection from a client system.

    SendData Method

    This method dispatches data to the remote computer. It is used for both the client and server systems.

    Connect Method

    The Connect method requests a connection to a remote computer.

    I am not going to discuss events here. You can find more Winsock details at the following address: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusingwinsockcontrol.asp

    As stated earlier, this article describes the creation of two applications -- one server and one client. The database used in the sample is also provided with the code. The database -- Prices.mdb --. contains a single table with the fields item number and price. The client sends the item number to the server and the server retrieves the price against that item number from the database and sends it back to the client. One of the current trends in software development is the issue of thick clients versus thin clients. A thick client is basically an application that performs the bulk of the processing on the individual client PC, whereas a thin client performs the processing on the server.

    Creating the Client

    Follow the steps below:

    1. Start a new EXE project.
    2. Add a Winsock control to your application.
    3. Add all the controls to the form (see the application for details).
    Here is the complete code:

    Option Explicit

    Private Sub cmdClose_Click()
    Winsock1.Close
    shpGo.Visible = False
    shpWait.Visible = False
    shpError.Visible = True
    End Sub

    Private Sub cmdConnect_Click()
    Winsock1.RemoteHost = "11.0.0.1" 'Change this to your host IP
    Winsock1.RemotePort = 1007
    Winsock1.Connect
    shpGo.Visible = True
    txtItem.SetFocus
    End Sub

    Private Sub cmdSend_Click()
    If Winsock1.State = sckConnected Then
    Winsock1.SendData txtItem.Text
    shpGo.Visible = True
    Label3.Caption = "Sending Data"
    Else
    shpGo.Visible = False
    shpWait.Visible = False
    shpError.Visible = True
    Label3.Caption = "Not currently connected to host"
    End If
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim sData As String
    Winsock1.GetData sData, vbString
    'Label1.Caption = sData
    txtPrice.Text = sData
    Label3.Caption = "Received Data"
    shpGo.Visible = True
    shpWait.Visible = False
    shpError.Visible = False

    End Sub

    Private Sub Winsock1_SendComplete()

    Label3.Caption = "Completed Data Transmission"

    End Sub

    Creating the Server

    The server portion of the price lookup example is designed to accept the item number sent from the client and look up the associated price in a database. The server than sends the information back to the client. There is a file named "path.txt" in the folder called "Server." Locate that file and change the database path in that file to the database's location on your machine. The connection to the database is made in the DataArrival event of the Winsock control. The following code segment opens the database and finds the first occurrence of the value in sItemData. When the record is found, the value contained in the price field is sent back to the client.


    ' Get clients request from database
    strData = "Item = '" & sItemData & "'"

    rs.Open "select * from prices", strConnect, adOpenKeyset, adLockOptimistic
    rs.Find strData
    strOutData = rs.Fields("Price")

    Follow the steps below to create the server:

    1. Start a new standard EXE in VB.
    2. Add the Winsock control to your application.
    3. Add the controls to the form as shown in the accompanying code (see the folder named "Server").
    Here is the complete code:

    Option Explicit
    Dim iSockets As Integer
    Dim sServerMsg As String
    Dim sRequestID As String

    Private Sub Form_Load()

    Form1.Show
    lblHostID.Caption = Socket(0).LocalHostName
    lblAddress.Caption = Socket(0).LocalIP
    Socket(0).LocalPort = 1007
    sServerMsg = "Listening to port: " & Socket(0).LocalPort
    List1.AddItem (sServerMsg)
    Socket(0).Listen
    End Sub

    Private Sub socket_Close(Index As Integer)
    sServerMsg = "Connection closed: " & Socket(Index).RemoteHostIP
    List1.AddItem (sServerMsg)
    Socket(Index).Close
    Unload Socket(Index)
    iSockets = iSockets - 1
    lblConnections.Caption = iSockets

    End Sub

    Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    sServerMsg = "Connection request id " & requestID & " from " & Socket(Index).RemoteHostIP
    If Index = 0 Then
    List1.AddItem (sServerMsg)
    sRequestID = requestID
    iSockets = iSockets + 1
    lblConnections.Caption = iSockets
    Load Socket(iSockets)
    Socket(iSockets).LocalPort = 1007
    Socket(iSockets).Accept requestID
    End If

    End Sub

    Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)

    Dim sItemData As String
    Dim strData As String
    Dim strOutData As String
    Dim strConnect As String


    ' get data from client
    Socket(Index).GetData sItemData, vbString
    sServerMsg = "Received: " & sItemData & " from " & Socket(Index).RemoteHostIP & "(" & sRequestID & ")"
    List1.AddItem (sServerMsg)

    'strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Prices.mdb;Persist Security Info=False"
    Dim strPath As String

    'Change the database path in the text file

    Dim fso As New FileSystemObject, txtfile, _
    fil1 As File, ts As TextStream

    Set fil1 = fso.GetFile("path.txt")
    ' Read the contents of the file.
    Set ts = fil1.OpenAsTextStream(ForReading)
    strPath = ts.ReadLine
    ts.Close
    Set fso = Nothing

    strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;Data Source=" & strPath & _
    "; Mode=Read|Write"

    Dim rs As New ADODB.Recordset

    ' Get clients request from database
    strData = "Item = '" & sItemData & "'"

    rs.Open "select * from prices", strConnect, adOpenKeyset, adLockOptimistic
    rs.Find strData
    strOutData = rs.Fields("Price")

    'send data to client
    sServerMsg = "Sending: " & strOutData & " to " & Socket(Index).RemoteHostIP
    List1.AddItem (sServerMsg)
    Socket(Index).SendData strOutData

    End Sub

    Running the Example

    1. Create the executable for both applications.
    2. Launch both applications.
    3. Click the Connect button.
    4. Enter a value from 0 to 6 (currently the database contains only six records, error handling is not done in this code; you can add the error handling yourself) and click the Lookup button. The associated price will be displayed in the price field.

    About the Author

    S.S. Ahmed is a senior software engineer in a software development company that specializes in Web application development. To contact Ahmed with questions or comments, e-mail him at ss_ahmed1@hotmail.com.

    Winsock TCP/IP Chat Program

    recently needed TCP/IP functionality for an office application I am developing (an interface between our lab information system and vendor-provided testing equipment), and in creating the demo I found it first helpful to design a chat program in order to get the basics of using the VB6 Winsock control down. This demo is the result of those tests, and it works! To become a full-featured application will require additional features, but this is more than a skeleton so should provide a good starting base.

    In constructing the app form my use I had two specific requirements. First, for configuration and identification, the app needed to pass some initial info between the connections when first established, data that was not part of its ongoing conversation. In this demo I turned that requirement into a mechanism for sending the name of the user between the client and the server.

    The second criteria was more elaborate ... I needed a mechanism to automatically reconnect to each other regardless of which session (client or server) was experiencing the network problem, and to do so without user intervention. I accomplished this as well, although that code is not included in this demo.

    There are no APIs in this demo. I felt that it would first be prudent to get the workings down pat using the Winsock control, then to learn from the code in order to adapt it to the Winsock API (if even necessary).

    While much of the code in both the server and client portions of the chat are similar, there are sufficient differences to warrant the copious commenting that follows in the code. Each portion of the app contains three textboxes (txtSend, txtReceive and txtErr) that handle the user's input, the Winsock received data, and Winsock errors respectively. Some of the error code previously displayed in txtErr was moved to a more logical MsgBox for this demo, so its use here is much more limited than in my original design.

    A Winsock connection is made by one application performing the server task of listening for connections, and another acting as a client that initiates that request. Therefore for simplicity the two forms are named frmServer and frmClient. (In the Form Code section is the illustration showing the layout and names of the controls required.) Interestingly (and conveniently for debugging), because the forms carry on their conversation is via system ports, this project can (and was) built by adding both forms into a single project. Moving to separate projects for the final compile as client and server will involve only removing one form, creating a new project and loading it, and removing the frmClient.Show line from the frmServer load event.

    In use, the server is moved into its Listening mode awaiting a request to connect. When a client contacts the server via the port required, a numeric ID is exchanged that identifies the session, and the conversations between the two apps can take place. Should the client attempt to connect to a port on which there is no server listening, an error message is generated. Similarly, should either attempt to transmit data to a port where there is no app to receive the data, an error is generated. Once the server and client perform the initial connection and exchange the session ID, I have coded the routine to transmit the username (currently stored in a variable) across to the other app. When this has been received, the captions of the app are adjusted, a "got that name" flag is set, and further conversations are relayed to the txtReceive boxes.


    BAS Module Code
    None.


    Form Layout: frmServer and frmClient
    Since both forms use the same controls and control names (except for the Winsock control names), I suggest that you create the from as shown and name it frmServer. This will be the application startup form. Name the Winsock control added to this form "tcpServer", and save the file as "frmServer.frm". Add a second form, copy all controls onto it, change the name of the Winsock control on the new form to "tcpClient", and save as frmClient. You should now have a project with the two forms as below, and no errors or conflicts when loading and running the empty project using Run/Start with Full Compile.



    Form Code: frmServer
    Paste the following code into the General Declarations section of frmServer:

    Option Explicit
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Copyright ©1996-2009 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.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim myname As String
    Private isConnectedFlag As Boolean
    Private sClientChatName As String 'holds the name of connected user
    Const msgTitle As String = "VBnet Winsock Chat Server Demo"

    Private Sub cmdConnect_Click()

    'This method first assures that the server
    'Winsock control is closed, then assigns a
    'port to control's LocalPort for use as the
    'server (the port specified must be numeric -
    'it can not be a friendly name from the system's
    'services file. Once assigned, invoke the
    'Winsock Listen method.

    tcpServer.Close
    tcpServer.LocalPort = 1544
    tcpServer.Listen

    'If the connection was successful, the control's
    'state wil be 'sckListening'
    If tcpServer.State = sckListening Then

    Me.Caption = "TCP Server : Listening"
    cmdDisconnect.Caption = "Stop Listening"
    cmdDisconnect.Enabled = tcpServer.State = sckListening
    cmdConnect.Enabled = tcpServer.State = sckClosed

    End If

    'if there was an error in the connection,
    'display it in the txtErr box

    txtErr.Text = Err.Description

    End Sub


    Private Sub cmdDisconnect_Click()

    If tcpServer.State = sckListening Or _
    tcpServer.State = sckConnected Then

    tcpServer.Close
    isConnectedFlag = tcpServer.State = sckConnected
    Me.Caption = "TCP Server Closed"

    cmdDisconnect.Enabled = isConnectedFlag = True
    cmdConnect.Enabled = isConnectedFlag = False

    End If

    End Sub


    Private Sub cmdSend_Click()

    Call TransmitMessage

    End Sub


    Private Sub Form_Load()

    txtErr.Text = ""
    txtSend.Text = ""
    txtReceive.Text = ""
    myname = "server"
    Label2.Caption = myname
    frmClient.Show 'Show the client form.

    End Sub


    Private Sub Form_Unload(Cancel As Integer)

    tcpServer.Close
    Unload frmClient
    Set frmClient = Nothing
    Set frmServer = Nothing

    End Sub


    Private Sub tcpServer_Close()

    'we need this flag check as showing a
    'msgbox in this event will cause the
    'event to fire again on closing the
    'msgbox, causing an endless loop.

    If isConnectedFlag = True Then
    If tcpServer.State = sckClosing Then

    'assure we avoid the loop
    isConnectedFlag = False

    'update the caption
    Me.Caption = "TCP Server Closing"

    'and inform the user
    MsgBox "The connection to ' " & sClientChatName & _
    " ' has been unexpectedly terminated.", _
    vbExclamation Or vbOKOnly, msgTitle

    'close to allow reconnection
    tcpServer.Close

    cmdDisconnect.Enabled = isConnectedFlag
    cmdConnect.Enabled = Not isConnectedFlag

    End If
    End If

    Me.Caption = "TCP Server Closed"

    End Sub


    Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)

    'Check if the control's State is closed. If not,
    'close the connection before accepting the new
    'connection.
    If tcpServer.State <> sckClosed Then
    tcpServer.Close
    End If

    'Accept the request with the requestID parameter.
    tcpServer.Accept requestID

    End Sub


    Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)

    Dim strData As String 'holds incoming data
    Dim buff As String

    'avoid cycles by placing the most-likely
    'condition first in the If..Then statement
    If isConnectedFlag = True Then

    'connection is established, and isConnectedFlag
    'is set, so any incoming data is part of the chat
    tcpServer.GetData strData

    'if there is text in txtReceived, (not the
    'first line received) then we need a crlf
    'between lines. This also provides a place to
    'preface the string with the sender's name.
    If Len(txtReceive.Text) Then
    buff = buff & vbCrLf & sClientChatName & " :" & vbTab & strData
    Else
    buff = buff & sClientChatName & " :" & vbTab & strData
    End If

    'this assigns the new string to the end of
    'txtReceived, and scrolls it into view.
    With txtReceive
    .SelStart = Len(txtReceive.Text)
    .SelText = buff
    .SelStart = Len(txtReceive.Text)
    End With

    'clear the user-input textbox (if desired)
    'txtSend.Text = ""


    Else

    'set the isConnectedFlat to avoid entering
    'this condition again during this session
    isConnectedFlag = True

    'isConnectedFlag was false, so the first data
    'received from the connected client will be
    'the name of the user. Save this for use when
    'posting subsequent data to txtReceived.
    tcpServer.GetData strData
    sClientChatName = strData
    Me.Caption = "TCP Server : Chatting with " & sClientChatName

    'be friendly and transmit your name to the client
    tcpServer.SendData myname

    'change the caption to the disconnect button
    cmdDisconnect.Caption = "Disconnect"

    txtSend.SetFocus

    End If

    End Sub


    Private Sub tcpServer_Error(ByVal Number As Integer, _
    Description As String, _
    ByVal Scode As Long, _
    ByVal Source As String, _
    ByVal HelpFile As String, _
    ByVal HelpContext As Long, _
    CancelDisplay As Boolean)

    MsgBox "tcpServer Error: " & Number & vbCrLf & Description, _
    vbExclamation Or vbOKOnly, msgTitle

    CancelDisplay = True
    tcpServer.Close

    End Sub


    Private Sub txtSend_KeyPress(KeyAscii As Integer)

    If KeyAscii = vbKeyReturn Then
    Call TransmitMessage
    End If

    End Sub


    Private Sub TransmitMessage()

    Dim buff As String

    'in this method, we don't want to
    'first test for a valid connection
    '(ie If tcpClient.State = sckConnected)
    'in order to generate the appropriate
    'error message to the user.

    On Local Error GoTo TransmitMessage_error

    tcpServer.SendData txtSend.Text

    'if there is text in txtReceived, (not the
    'first line received) then we need a crlf
    'between lines. This also provides a place to
    'preface the string with the your name.

    If Len(txtReceive.Text) Then
    buff = buff & vbCrLf & myname & " :" & vbTab & txtSend.Text
    Else
    buff = buff & myname & " :" & vbTab & txtSend.Text
    End If

    'assign the new string to the end of
    'txtReceived, and scroll it into view.

    With txtReceive
    .SelStart = Len(txtReceive.Text)
    .SelText = buff
    .SelStart = Len(txtReceive.Text)
    End With

    'clear the input textbox
    txtSend.Text = ""

    TransmitMessage_exit:

    Exit Sub

    TransmitMessage_error:

    Select Case Err
    Case sckBadState:

    MsgBox Err.Description & "." & vbCrLf & _
    "The server is not connected to a client.", _
    vbExclamation Or vbOKOnly, msgTitle

    Case Else

    MsgBox Err.Description & ".", _
    vbExclamation Or vbOKOnly, msgTitle

    End Select

    Resume TransmitMessage_exit

    End Sub

    Form Code: frmClient
    Paste the following code into the General Declarations section of frmClient:

    Option Explicit

    Dim myname As String
    Private isConnectedFlag As Boolean
    Private sClientChatName As String 'holds the name of the connected user
    Const msgTitle As String = "VBnet Winsock Chat Client Demo"

    Private Sub cmdDisconnect_Click()

    If tcpClient.State = sckConnected Then

    tcpClient.Close
    isConnectedFlag = tcpClient.State = sckConnected
    Me.Caption = "TCP Client Closed"

    cmdDisconnect.Enabled = isConnectedFlag
    cmdConnect.Enabled = Not isConnectedFlag

    End If

    End Sub


    Private Sub cmdSend_Click()

    Call TransmitMessage

    End Sub


    Private Sub Form_Load()

    txtErr.Text = ""
    txtSend.Text = ""
    txtReceive.Text = ""
    myname = "rgb"
    Label2.Caption = myname

    End Sub


    Private Sub cmdConnect_Click()

    'The name of the Winsock control is tcpClient.
    'To specify a remote host, you can use
    'either the IP address (ex: "14.15.15.16") or
    'the computer's "friendly" name (LocalHostName)
    'as shown here.

    tcpClient.RemoteHost = tcpClient.LocalHostName
    tcpClient.RemotePort = 1544

    'call the Connect method to open a connection.
    'If the call fails, the tcpClient_Error event will fire

    tcpClient.Connect

    cmdConnect.Enabled = tcpClient.State = sckClosed


    connect_exit:
    Exit Sub

    End Sub


    Private Sub Form_Unload(Cancel As Integer)

    tcpClient.Close

    End Sub


    Private Sub tcpClient_Close()

    'we need this flag check as showing a
    'msgbox in this event will cause the
    'event to fire again on closing the
    'msgbox, causing an endless loop.


    If isConnectedFlag = True Then
    If tcpClient.State = sckClosing Then

    'assure we avoid the loop
    isConnectedFlag = False

    'update the caption
    Me.Caption = "TCP Client Closing"

    'and inform the user
    MsgBox "The connection to ' " & sClientChatName & _
    " ' has been unexpectedly terminated.", _
    vbExclamation Or vbOKOnly, msgTitle

    'close to allow reconnection
    tcpClient.Close

    cmdDisconnect.Enabled = isConnectedFlag
    cmdConnect.Enabled = Not isConnectedFlag

    End If
    End If

    Me.Caption = "TCP Client Closed"

    End Sub


    Private Sub tcpClient_Connect()

    If isConnectedFlag = False Then

    'this is the first time connecting to the
    'server, so be friendly and transmit your
    'name to the client

    If tcpClient.State = sckConnected Then
    tcpClient.SendData myname
    End If

    txtSend.SetFocus

    End If

    cmdSend.Enabled = tcpClient.State = sckConnected
    cmdDisconnect.Enabled = tcpClient.State = sckConnected

    End Sub


    Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)

    Dim strData As String 'holds incoming data
    Dim buff As String

    'avoid cycles by placing the most-likely
    'condition first in the If..Then statement

    If isConnectedFlag = True Then

    'connection is established, and isConnectedFlag
    'is set, so any incoming data is part of the chat

    tcpClient.GetData strData

    'if there is text in txtReceived, (not the
    'first line received) then we need a crlf
    'between lines. This also provides a place to
    'preface the string with the sender's name.

    If Len(txtReceive.Text) Then
    buff = buff & vbCrLf & sClientChatName & " :" & vbTab & strData
    Else
    buff = buff & sClientChatName & " :" & vbTab & strData
    End If

    'this assigns the new string to the end of
    'txtReceived, and scrolls it into view.

    With txtReceive
    .SelStart = Len(txtReceive.Text)
    .SelText = buff
    .SelStart = Len(txtReceive.Text)
    End With

    'clear the user-input textbox (if desired)
    'txtSend.Text = ""


    Else

    'set the isConnectedFlat to avoid entering
    'this condition again during this session

    isConnectedFlag = True

    'isConnectedFlag is false, so the first data
    'received from the connected client will be
    'the name of the user. Save this for use when
    'posting subsequent data to the txtReceived box.

    tcpClient.GetData strData
    sClientChatName = strData

    Me.Caption = "TCP Client : Chatting with " & sClientChatName

    End If

    End Sub


    Private Sub tcpClient_Error(ByVal Number As Integer, _
    Description As String, _
    ByVal Scode As Long, _
    ByVal Source As String, _
    ByVal HelpFile As String, _
    ByVal HelpContext As Long, _
    CancelDisplay As Boolean)

    Select Case Number
    Case 10061

    MsgBox "Error: " & Number & vbCrLf & Description & _
    vbCrLf & vbCrLf & _
    "The VBnet Winsock Chat Demo server is not running, " & _
    "or has not properly established a connection.", _
    vbExclamation Or vbOKOnly Or vbMsgBoxSetForeground, _
    msgTitle

    Case 2: MsgBox "2"
    Case 3: MsgBox "3"

    Case Else
    MsgBox "Error: " & Number & vbCrLf & Description, _
    vbOKOnly Or vbExclamation Or vbMsgBoxSetForeground, _
    msgTitle

    End Select

    CancelDisplay = True
    tcpClient.Close

    're-enable to connect button
    cmdConnect.Enabled = tcpClient.State = sckClosed

    End Sub


    Private Sub txtSend_KeyPress(KeyAscii As Integer)

    If KeyAscii = vbKeyReturn Then
    Call TransmitMessage
    End If

    End Sub


    Private Sub TransmitMessage()

    Dim buff As String

    'in this method, we don't want to
    'first test for a valid connection
    '(ie If tcpClient.State = sckConnected)
    'in order to generate the appropriate
    'error message to the user.

    On Local Error GoTo TransmitMessage_error

    tcpClient.SendData txtSend.Text

    'if there is text in txtReceived, (not the
    'first line received) then we need a crlf
    'between lines. This also provides a place to
    'preface the string with the client name.

    If Len(txtReceive.Text) Then
    buff = buff & vbCrLf & myname & " :" & vbTab & txtSend.Text
    Else
    buff = buff & myname & " :" & vbTab & txtSend.Text
    End If

    'assign the new string to the end of
    'txtReceived, and scroll it into view.

    With txtReceive
    .SelStart = Len(txtReceive.Text)
    .SelText = buff
    .SelStart = Len(txtReceive.Text)
    End With

    'clear the input textbox
    txtSend.Text = ""

    TransmitMessage_exit:

    Exit Sub

    TransmitMessage_error:

    Select Case Err
    Case sckBadState:

    MsgBox Err.Description & "." & vbCrLf & _
    "The client is not connected to the server.", _
    vbExclamation Or vbOKOnly, msgTitle

    Case Else

    MsgBox Err.Description & ".", _
    vbExclamation Or vbOKOnly, msgTitle

    End Select

    Resume TransmitMessage_exit

    End Sub

    Examples relating to programming

    Table of Contents
    Section Description
    AOL and AIM Add-ons Examples relating to programming AOL or AIM add-ons.
    Fonts, Files, and Databases Examples dealing with fonts, files or databases.
    Games Examples on games or things game related.
    Images Examples dealing with images or the manipulation of them.
    Internet Examples that have to do with the Internet.
    Menus Examples on dealing with menus.
    Special Effects Special effect examples.
    Window Manipulating Examples dealing with the manipulation of windows.
    Miscellaneous Examples that don't fit any where else.

    AOL and AIM Add-on Examples
    Code Title Author Code Description Download
    Add Room To List (AOL6 and below) myst Add the memebers of an aol chat room to a list. Download
    AIM PW Decrypter beerbaron Shows how to decrypt aim passwords. [written in 2001] Download
    AIM Screenname And PW Extract ChiChis This code demonstrates how to extract AIM screennames from the registry and the decrypt the password. [written in 2000] Download
    AOL Chat Room Hook Example Craig Jasper, Jr. Subclassing example that shows how to determine if a newly created AOL window is an AOL chat room. [Requires SpyWorks 6; Written in VB6; Created in Win2000; Only tested for AOL 5.0 Revision 205.103] Download
    AOL Hot Keys Example Craig Jasper, Jr. An example that shows how easy it is to implement HotKeys for AOL using the SpyWorks WinHook control. [Requires a licensed version of SpyWorks 6 WinHook control - DWSHK36.OCX; Tested with AOL5 and AOL6] Download
    AOL HTML Extractor Craig Jasper, Jr. An example to demonstrate how to get the HTML that is the basis behind AOL's RICHCNTL via the Windows clipboard, as well as how to extract the URL data via the Windows clipboard. [Tested on AOL 7.0 Revision 4114.256] Download
    AOL4 Chat/IM/EMail Examples Shadow-X Three examples that show how to send text to chat room, send text in IMs, and send text in email. Download
    AOL7 Chat Sender Example Source Shows how to send text to AOL7 chat rooms. Download
    AOL7 Instant Keyword Example Source Shows how to visit a website via the toolbar icon, keyword window textbox, and then keyword window icon. Download
    AOL7 Instant Message Sender Example Source An example that shows how to send an instant message in AOL7. Download
    AOL7 Write EMail Example Source Shows how to send email in AOL7. Download
    Auto Fader Xhandar This is a 1 - 20 color auto-fader example for AOL. [Requires Dwsbc36.ocx] [Samples dos32.bas and patorjkfaderv2.bas] Download
    Elite textbox patorjk This shows you one way you can change how text appears in a textbox as it's being typed. Download
    Fader Example sungod This is an example on how to make a fader program. It has a pretty cool way of preview fading the text. Download
    Macro Font Example patorjk This is an example that shows you two different ways to display macro fonts for macro shops. Download
    MailBomb Fixer Example patorjk This is an example of a mailbomb fixer for aol4. It shows you how to get the mail list then scroll down it checking the item's text with the item you want to delete. Download
    Room Buster/Server Helper Xhandar This is an project showing how to make a room buster with a server helper. Download
    Scrambler Game Example martyr An example on how to make a chat room scrambler. [Note: Example is missing files and no longer works] Download
    Sir's AOL/AIM Example SiR This is an example project that shows you the basics on how to make an AOL/AIM program. [comes with the sir vb6 bas] Download
    Subclass Chat Send Craig Jasper, Jr. An example of subclassing an AOL 6.0 chat room's Send button and detecting when the Enter key is pressed in the RICHCNTL. Created for a ccom program, so the chat room doesn't have to see all of your commands. [Requires SpyWorks 6; Written in VB6 with Service Pack 5 installed; Created in Win2000 with Service Pack 2 installed; Only tested for AOL 6.0 Revision 4097.10523] Download

    Fonts, Files, and Databases
    Code Title Author Code Description Download
    Address Book DataBase Brian Smith aka local An example of how to create an address book. [patorjk.com VB Contest Winner] Download
    Address Book Example Eric Osterheldt aka Deep Arctic An example on how to create an address book. [Missing]
    File Explorer rude VB example of a file explorer. Download
    File Associations (File Type Generator) Adam T Shows how to create file associations so when you double click a certain file type it will open in a certain program. Download
    Font Explorer Xhandar Lets you easily view your system's fonts by using an explorer-like interface. Download
    Font Loading Example gozer This example shows you how you can use win32 api functions to quickly load all of the fonts on your computer. Download
    Font Loading Example patorjk This example shows you one way you can speed up the loading of the fonts through a list of them to a file, then checking to see if any new ones have been added. Download
    Open and Save Text Files patorjk This is a pretty simple example. I made it because I get a lot of questions on how to open and save text files. Download
    Random Access Example Eric Osterheldt aka Deep Arctic Shows how to open and save a file in Random mode. Commonly used for databases. Download

    Games
    Code Title Author Code Description Download
    Frogger John Harper aka Digital Rampage A VB version of the classic video game Frogger. [patorjk.com VB Contest Winner] Download
    High Score List Example patorjk This is an example I made to show you one way on how you can make a high score feature for your project. Download
    Mine Sweeper Game Example unknown This is an example on how to make the popular windows game Mine Sweeper. Download
    Rock, Paper, Scissors Game Example Wiger A rock, paper, scissors game example, shows how to use the Select Case statement. Download
    Sort List by Scores patorjk This is an example that shows you how to sort a listbox by the score a player has (sort of like the ones in chat room scrambler games). Download
    Tic Tac Toe Eric Osterheldt aka Deep Arctic This is an example that shows you how to sort a listbox by the score a player has (sort of like the ones in chat room scrambler games). Download

    Images
    Code Title Author Code Description Download
    Add Scrollbars to a Picturebox patorjk This example shows you how you can add scrollbars to a picturebox. Download
    Fade One Picture into Another Picture patorjk This is an example on how to fade one image into another image using vb code. Download
    Icon Editor Herman Liu An example on how to make an Icon Editor in VB. Download
    Image Map Maker Example Xhandar An example on how to create an image map maker (one that generates image maps for html coding). Download
    Macro Converter patorjk This takes pictures and turns them into text (or macros). I had some people tell me they were having some trouble with the macro converting code in the source code section, so I thought I'd post up an example on a macro converter. Download
    Mosaic Maker patorjk An example on how to make a photomosaic image with one image (sort of like the ones my mosaicer program makes excepts with only one image). Download
    Palette Writer Xhandar Shows how to write microangelo palettes, microsoft aplettes, and adobe color tables. Download
    Picture to HTML patorjk This is the source code to the 1.5 version of my picture to macro program. Download
    Zoom-in on Pictures patorjk This is an example on how to zoom in on pictures. Sort of like how paint brush does with that little box. Download

    Internet
    Code Title Author Code Description Download
    Download File matis Shows how to download a file off of the internet from a VB program. [Requires the INet control] Download
    Firewall Example Dracula X An example on how to create a Firewall. Download
    FTP Program Example Unknown This is an example on how to make an ftp program. Download
    Get HTML matis Show how to get the source to a website using the inet control. Download
    IP Chat Example KnoB This is an IP chat that uses encryption to send data. Made in VB6. [Missing]
    Multiple Client Messenger Server Robert Cleaver This is an almost complete example of a multiple client messenger server that shows all online users and allows you to instant message them. Download
    SMPT Mailing Program Sean Mckeown - kow This is a simple version of how to make an smtp mailing program. Download
    Web Browser Example Garren aka Keith Escalade Very nice example on how to make a web browser and how it works. Download

    Menus
    Code Title Author Code Description Download
    Menu Effects dos Shows you how to change the font and selection colors in a menu. Make sure and read comments in the example so you don't end up crashing VB. Download
    Menu Effects face Another take on creating your own menu. This example uses vb forms and allows scroll out effects. Download
    Menu Effects Da Jokel Another example on menu effects, this one doesn't involve subclassing. Download
    Menu Effects casper Another example on menu effects, this one doesn't involve subclassing. Download
    Run Menu Example Synthesize Shows how to select an item in another program's menu. Download

    Special Effects
    Code Title Author Code Description Download
    Draw Border With API patorjk This example shows you how to use win32 api to draw lines and how to draw a border with a certain thickness. Download
    Form Background Fade patorjk All code in this example was rewritten. This gives your forms a cool fading top to bottom or Side to Side color effect. Download
    HTML Desktop Adam Wehmann Very cool. Create your own little desktop. Read readme.txt file for more instructions/info. [Missing]
    Moving Background Example Synthesize Creates a cool effect with a background that scrolls to the right. Download
    Mouse Move and Click Eric Osterheldt aka Deep Arctic Shows how to set the mouse position and then cause a mouse click in that spot. Download
    Multi-Line ToolTips Craig Jasper, Jr. This is an example on how to make Multi-Line ToolTips. Download
    Rounded Border Example Chris Neuner Example showing how to create a form with rounded borders. Download
    Shape a Form to a Bitmap dos Shows you how to shape a form to bitmap. Download

    Window Manipulating
    Code Title Author Code Description Download
    Api Spy patorjk This is an example on how to make a 32 bit drag and drop api spy. Download
    Basic API Coder Greenmonkey An example showing how to create a code generating program for finding windows. Also shows how to make it so the program can read add-ins. Download
    Code Generator For Window Finding Eric Osterheldt aka Deep Arctic Another example on how to create the code to find windows, this one however, can create the code in VB, VC++, and Delphi. Download
    Dock forms in VB shock Shows how to align one form next to another one. [Missing]
    Draw Pictures On Windows patorjk This is an example on how to draw an image onto another window. Like if you wanted to draw over an image on a toolbar of another program or draw over the button on another program. Download
    Find A Window's Siblings and Children patorjk Shows you how to find all of a window's siblings and children. Download
    Find Window Code Generator Example patorjk This is an example that shows how to create the code to find a window, just by knowing the window's handle. Download
    Form Docking Viper Shows how to make it so you can drag two forms at once. Ex: When you drag form1, if form2 is attached, it will be dragged along with form1. [Missing]
    Load From Old Position Adam V. aka sabre Shows how to load a program in the position it was in when it was last used. Download
    MDI & Dialog Example Eric Osterheldt aka Deep Arctic An example showing how to use MDIs and dialogs that they can use. Download
    Positions Example Pio Shows one use for registry entries. Move the form to where ever you want it, then click the x on the form. When you load it up the next time it will be where ever you closed it. Download

    Miscellaneous
    Code Title Author Code Description Download
    Addition (The Hard Way) Adam Wehmann Performs addition on any two positive numbers. Is able to add numbers larger than 2,147,483,647 (the max range for a Long data-type variable). Download
    Calculating Money Eric Osterheldt aka Deep Arctic Calculates money and shows one use for varibles of the currency type. Download
    Color Spy Example patorjk Shows a couple different ways on how to make a color spy. Download
    Compression Example sloat This is an example on RunLength Compression, also contains some unfinished work on LZW compression. Download
    Creating Controls at Runtime Clash An example of creating controls at runtime, how to drag them around, and how to delete them. Download
    Drag and Drop patorjk Ever want to know how to drag and drop images out of pictures? Check this example out. Download
    Drag and Drop Controls ChiChis This example shows you how to give the user the ability to move controls at runtime with ease. Download
    E-Note Flyman This is an example of a small little note taker. Takes less then 5mins to make, pretty cool and fun to play with. [Missing]
    Get ID3v2 Tag from an Mp3 Eric Osterheldt aka Deep Arctic Gets information from an MP3 like title, artist, album, etc. Download
    GetTickCount Example ChiChis Pretty simple example of the API call GetTickCount to get the amount of time since Windows was booted up. Download
    How to Create System Restore Points coolspot How to create system restore points (for Windows XP). This uses Windows Management Instrumentation (WMI) which Im told is only present in Windows 2000/XP. Download
    Key Logger patorjk This example shows you one way on how you can log the keys pressed on the users keyboard. Download
    Line Drawing Example Jim An easy way to draw lines on a form on mousedown. It doesn't use timers, or pictures boxes at all. Even better yet, its only a few lines on code. Download
    List Item Drag and Drop Example Eduardo Morcillo This example shows how to drag ListBox items using functions from comctl32.dll. Download
    List Item Drag and Drop Example patorjk This example shows you one way on how you can drag items from one list and put them in another. Download
    Math Expression Evaluator Adam Wehmann Shows out to evaluate math expressions given a string. Example: "5 * (3 + 1)" = "20". [patorjk.com VB Contest Winner] Download
    MCI Example Matt Hart An example on how to play mid files and avi files without custom controls. [Missing]
    MouseOver MouseOut Example gozer This example was written to show the different ways of using the api of mouse move stuff in the mousemove event. Like creating detecting when a mouse enters and leaves the object. Download
    MP3 Player Jason Hensley A basic example of using [Jason's] MP3 Class Module to create an MP3 Player that uses the winmm.dll (Uses Api). This was made using Visual Basic 6.0, but should work with any 32 Bit Visual Basic. Download
    MPlay3 hostyle Source code from mPlay3. Shows basic mp3 playing functions: play, pause, stop, mute, previous file and next file(play) buttons. It also has load last directory. Download
    String Encryption gozer Another way you can encrypt and decrypt text. This one's a bit more complicated than the other one. Download
    String Encryption Dracula X An example on how to encrypt and decrypt text. Download
    System Information Craig Jasper, Jr. An example on getting system information. [Made for Win2000] Download
    System Wide Hotkeys Craig Jasper, Jr. An example of system wide hotkeys without a third party control. [VB5 and up] [Missing]
    Tabstrip and Progressbar Control Example patorjk This is a small example on how to use the tabstrip control and the progressbar control. Download
    Time Left Example patorjk This is an example on how to calculate how much time it will take to preform certain tasks. The idea will only work with things that loop over and over. Download
    Treeview Example Shawn N. An example showing how to use the Treeview control found in MSComCtl.ocx. Download
    Windows Resource Meter Eric Osterheldt aka Deep Arctic A resource meter that displays phyiscal, virtual, and page file memory. [Missing]
    Windows Uptime Eric Osterheldt aka Deep Arctic An example that shows you how to find out how long Windows has been running (in months, weeks, hours, minutes, and seconds format). [Missing]
    Word Count Eric Osterheldt aka Deep Arctic Shows a way of counting the number of words in a text box. Uses some Windows API. Download
    Word Count Eric Osterheldt aka Deep Arctic Shows another way to count the number of words in a textbox. No Windows API functions are used here. [Missin

    VB3 samples

    VB3 samples. These samples illustrate 32-bit functions that normally cannot be done from 16-bit programs. They accomplish the feat through the use of a 16/32 thunking layer; in this case a public-domain DLL named CALL32 is used for the translation. Probably work with VB4/16, but not tested.

    TASKBR.ZIP - Put icons in the Taskbar Notification Area, also known as the Taskbar Tray. Modify the icons, delete them, show tool tips, and respond to mouse events. Includes MsgHook.VBX for receiving messages.

    REG32.ZIP - read and write Win95/NT registry values beyond the single Main Key allowed with 16-bit calls. Enumerate values, and work with multi-value keys.

    CALL32.ZIP- CALL32.DLL, required for the samples above. NOTE: At the time CALL32 was written, it was not compatible with "Chicago," so the documentation says it is NT only. As Win95 evolved it became compatible, so the documentation is in error. CALL32 works with all versions of 32-bit Windows.
    VB4/32-VB5/6 samples. Source code for some interesting problems.

    SUBCLASSED FILE DIALOG. The code presented here is amplified a bit from that which accompanied my article in the January '98 Visual Basic Programmer's Journal. This code demonstrates 1) a common dialog displayed without using the Comdlg32.ocx, and 2) subclassing of that dialog to place custom items on the dialog and to interact with it. The modified version presented here also demonstrates using the file dialog as a Folder Browser/Chooser. Advantages over the SHBrowseForFolder include a better look (which you can customize), better control over starting folder, and the ability to create folders within the dialog. Get the Source Code here (VB5/6).

    In an issue of Microsoft Developer Network News, in response to a question about what is required to produce a (32-bit Windows) screen saver, "Dr. GUI" responds in part: "1. To write screensavers for (32-bit Windows), you'll need the Win32 SDK. 2. Dr. GUI recommends using C++ for this task. You'll need C++ or at least C to interface with Windows...." The good doctor has presumably never seen our sample!

    JDSAVER - A fully functional code sample that implements all of the Win95/NT4 screen saver functions (/s /c /p /a). Puts a preview copy in the Display Properties Dialog, implements password protection, etc. A joint collaboration between Don Bradner and Jim Deutch. Available in VB4 and VB5/6 versions. JDSAVER.ZIP is the VB4 version and requires COMCTL32.OCX from VB4 pro. Also requires MsgHoo32.OCX, available in the MsgHook package below. JDSVRVB6.ZIP is the VB5/6 version, and requires no OCXs to work. Subclassing is handled with the AddressOf operator. Updated 8/20/2001.

    TASKBAR - Put icons in the Taskbar Notification Area, also known as the Taskbar Tray. Modify the icons, delete them, show tool tips. Another sample that has VB4 and VB5 versions. TSKVB4.ZIPis the VB4 version, requiring COMCTL32.OCX from VB4 pro and MsgHoo32.OCX, available in the MsgHook package below. TSKVB5.ZIP is the VB5 version, requiring no additional files.

    MSGHOOK.ZIP - Contains an executable file that installs both the 16 and 32-bit versions of MsgHook. Courtesy of Zane Thomas, Mabry Software, and Waite Group Press.

    REGVB4.ZIP- Most registry functions are demonstrated in the form of a functional registry editor, ala REGEDIT.EXE. Not intended to replace REGEDIT, but simply to demonstrate the functions. Req COMCTL32.OCX from VB4 pro.

    REGVB5.ZIP- Same as REGVB4, but fixes problems that make that file not work correctly in VB5. Req COMCTL32.OCX from VB5 pro.

    Read and write to any registry value! Why be limited to getsetting when you need information in the registry? Here is source for a registry read function limited only by your access permissions.

    Similarly, here is source for code to write any value in the registry.

    ICONXT.ZIP - demonstrates the extraction of large and small icons from an .EXE file that is not running.