The Winsock Control

The Winsock ActiveX control provided in Visual Basic 6 handles the low-level work of setting up, maintaining, and tearing down TCP connections. Your Visual Basic code need only supply the address of a server to talk to and the port on which to request a connection. Typically you will obtain the email server address either from your company’s network administrator or from your Internet service provider (ISP). As already mentioned, the port will be either 25 or 110, depending on whether you’re sending email or retrieving it. For the ensuing discussion, I will assume that you are familiar with ActiveX controls in general—that is, you know how to add a control to a form, how to set and read properties in code and at design time, and how to call methods.

By default, the Winsock control doesn’t appear in your Toolbox. To add it to the Toolbox for your project, from the Visual Basic menu choose Project Components. The Components dialog box appears, as shown in Figure A-1.

The Components dialog box

Figure A-1. The Components dialog box

Scroll down the list of components until you find “Microsoft Winsock Control 6.0”. Select the checkbox if it’s not selected already, then click OK. After doing so, you’ll see the Winsock control in your Toolbox. (If you don’t see the Toolbox at all, choose View Toolbox from the Visual Basic menu.) The Toolbox with the Winsock control’s icon is shown in Figure ...

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.