Client / Server Communications
for Visual Basic
Programmer's Manual
(CSC_4VB)
Version 4.0
April 11, 2007
This software is provided as-is.
There are no warranties, expressed or implied.
Copyright (C) 2007
All rights reserved
MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815
Voice : 1.256.881.4630
FAX : 1.256.880.0925
web : www.marshallsoft.com
MARSHALLSOFT is a registered trademark of MarshallSoft Computing.
1 Introduction
1.1 Features2 CSC Library Overview
1.2 Documentation Set
1.3 Example Program
1.4 Installation
1.5 Uninstalling
1.6 Pricing
1.7 Updates
1.8 Keycode (License Key)
2.1 Dynamic Link Libraries3 Compiler Issues
2.2 Using the CSC Library
2.3 Win32 STDCALL and DECLSPEC
2.4 Dynamic Strings
2.5 CSC4VB Class
2.6 VB.Net and Visual Studio
2.7 Visual Basic for Applications (VBA)
2.8 PowerBuilder
2.9 Using Threads
2.10 Adding CSC to Your Project
2.11 Example Client/Server Protocol
2.12 Error Display
3.1 Compiling CSC4 Example Programs
3.2 Compiling Example Programs
3.3 Explicitly Loading CSC32.DLL
4.1 CSCVER5 Revision History
4.2 CLIENT
4.3 SERVER
4.4 FILEGET
4.5 FILEPUT
4.6 AUTH_C
4.7 AUTH_S
4.8 FileSrv
4.9 FileCli
4.10 Hello
4.11 Download
The Client / Server Communications Library for Visual Basic (CSC4VB) is a component library of functions used to create server and client programs that can communicate with each other across any TCP/IP network such as the Internet or a private network (intranet or LAN [local area net]). CSC uses the standard Windows API (Application Programmer's Interface) and Windows Sockets API for all communication calls.
The CSC4VB component library supports and has been tested with all versions of Microsoft Visual Basic including Visual Basic .NET. CSC4VB includes numerous VB and VB. NET example programs that demonstrate client/ server protocols, including examples that connect to HTTP (web) and POP3 servers. All programs will compile using VB-4.0 through VB-6.0.
A Win32 DLL (Dynamic Link Library) is provided. CSC runs under all versions of Windows (95/98/ME/2000/NT/XP/VISTA). The Client / Server Communications Library SDK DLL (CSC32.DLL) can also be used from any language (C++, C++ .NET, Visual C#, Borland Delphi, Visual FoxPro, COBOL, Xbase++, Visual dBase, etc.) capable of calling the Windows API.
CSC4VB functions can also be called from Power Builder as well as VBA (Visual Basic for Applications) languages such as Excel, Microsoft Office and Access.
The Client/Server Communications Programmer's Manual provides information needed to compile programs using CSC in a Visual Basic or VB. NET environment.
When comparing the Client/Server Communications Library against our competition, note that:
For the latest version of the CSC software, see
http://www.marshallsoft.com/client-server-communication.htm
Our goal is to provide a robust communication component library that you and your customers can depend upon. A fully functional evaluation version is available. Contact us if you have any questions.
Some of the many features of the Client/Server Communications Library component are as follows:
CSC can also be used to communicate with other CSC programs, or they can be used to communicate with other TCP programs such as DNS, POP3, SMTP, FTP, HTTP, etc.
A good selection of Visual Basic (and VB.NET) example programs with full source code is included. Refer to Section 6 for more details on each of the example programs.
cscver Displays CSC version and build
auth_c Authenticating client.
auth_s Authenticating server.
client Simple client example program.
FileGet Receives a file.
FilePut Sends a file.
server Simple server example program.
FileSrv File server example program.
FileCli File client example program.
Hello Demonstrates use of CSC class.
Download Downloads file from web server.
The complete set of documentation consists of three manuals in three formats. This is the first manual (CSC_4VB) in the set.
The CSC_4VB Programmer's Manual is the language specific (Visual Basic and VB.NET) manual. All language dependent programming issues are discussed in this manual. Information needed to compile your programs in a VB environment is provided in this manual.
The CSC User's Manual (CSC_USR) discusses language independent issues. Information on Client / Server protocols as well as purchasing and license information is provided in the manual.
The CSC Reference Manual (CSC_REF) contains details on each individual CSC function.
Each manual comes in three formats:
The documentation is also provided on our web site at
http://www.marshallsoft.com/csc4vb.htm
The following code segment attempts to connect to the server.
DataSock = cscClient(HostName, HostPort)
If DataSock < 0 Then
Call DisplayError(Client, Code, "cscClient fails")
Code = cscRelease()
Exit Sub
End If
' wait for greeting message from server
Call DisplayText(Client, "Awaiting greeting message...")
' send WM_LBUTTONDOWN message when data is ready to be read
Code = cscDataMessage(Client.bReady.hWnd, DataSock, WM_LBUTTONDOWN)
Also see the example programs in the APPS sub-directory.
Uninstalling CSC4VB is very easy. CSC does NOT modify the registry. First, delete the CSC4VB project directory created when installing CSC4VB. Second, delete CSC32.DLL from your Windows directory, typically C:\WINDOWS for Windows 95/98/Me/XP/2003/Vista or C:\WINNT for Windows NT/2000.
A developer license for the Client/Server Communications Library can be registered for $115 (or $195 with source code [ANSI C] to the library DLL). Purchasing details can be found in Section 1.3, "How to Purchase", of the CSC User's Manual (CSC_USR). (http://www.marshallsoft.com/csc_usr.htm#Section_1.3)
Also see INVOICE.TXT or http://www.marshallsoft.com/order.htm
When you register a developer license for CSC4VB, you will receive a registered DLL plus a license file (CSCxxxx.LIC) that can be used to update your registered DLL's for a period of one year from purchase. Updates can be downloaded from
http://www.marshallsoft.com/oem.htm
After one year, your license must be updated if you want to be able to download updates. Your license can be updated for $30 if ordered within one year of the original purchase (or previous update). After one year, licenses can be updated for $55. Updates to the source code can be purchased for $50.
Note that the registered CSC DLL does not expire.
CSC32.DLL has a keycode encoded within it. Your keycode is a 9 or 10 digit decimal number (unless it is 0), and will be found in the file KEYCODE.H. The keycode for the evaluation version is 0. You will receive a new key code when registering. The KEYCODE is passed to cscAttach.
If you get an error message (value -74) when calling cscAttach, it means that the keycode in your application does not match the keycode in the DLL. After registering, it is best to remove the evaluation version of the CSC DLL from the Windows search path.
The Client/Server Communication Library component is a Win32 dynamic link library (DLL). A DLL is characterized by the fact that it need not be loaded until required by an application program and that only one copy of the DLL is necessary regardless of the number of application programs that use it. Contrast this to the traditional static library that is bound to each and every application that uses it at link time.
An important advantage that DLLs have over other "popular" library formats such as VBX or OCX is that DLLs are callable by all Windows applications. Since DLLs are the building blocks of the Windows Operating System, they will not be replaced by a "newer technology".
The Client/Server Communications Library (CSC) has been tested on multiple computers running Windows 95/98, Windows Me, Windows NT4, Windows 2000, Windows XP and Windows Vista.
The CSC4VB library has also been tested with several Visual Basic compilers, from VB_4.0 .0 through VB_6.0 .0 and VB.Net. CSC can also be used with Power Builder as well as 32-bit VBA applications such as Microsoft Office, EXCEL and ACCESS.
The SETUP installation program will copy the Lib's and DLL to your Windows directory. Refer to Section 1.4 "Installation".
CSC32 is written in ANSI C and is compiled using the _stdcall and _declspec keywords. This means that CSC32 uses the same calling conventions and file naming conventions as the Win32 API. In particular, function names are NOT decorated. There are no leading underscores or trailing "@size" strings added to function names.
The CSC32.DLL functions may be called from any Windows application program capable of calling the Windows API provided that the proper declaration file is used.
The Visual Basic language uses a technique known as "garbage collection" to manage string space at runtime and may be called internally at any time by the Visual Basic runtime, asynchronous to what you may be doing in your code.
When passing a string buffer to a DLL function into which text will be copied, it is strongly recommended that the local string be allocated immediately before use. For example, a string buffer is passed to the user defined dllGetMessage function , which copies a text message into it. Note that SPACE$(80) is called immediately before dllGetMessage.
Dim Code As Integer
Dim Buffer As String * 80
' allocate buffer just before call to dllGetMessage
Buffer = SPACE$(80)
' copy message into 'Buffer'
Code = dllGetMessage(Buffer, 80)
' message text is now in 'Buffer'
This technique is not necessary for passing a string to a DLL function, only when passing a buffer to a DLL into which data is to be placed by the DLL function.
The CSC class "cscClass" (cscClass.cls) is a Visual Basic class wrapper for making calls to CSC32.DLL. The class name for each function is the same as the DLL function, except the leading "csc" is replaced by "f".
The functions that return strings do so by use of the "String Result" property. Instantiate cscClass as any other class in VB:
Dim X As New cscClass
Classes were added to Visual Basic beginning with version 5.0, and are required in order to compile cscClass
There are a few differences between VB_4.0 /5/6 and VB.NET/VS Studio that affect writing programs that use CSC.
Buffer = Space(80)
Code = cscGetString(0, CSC_GET_REGISTRATION, Buffer, 80)
The Client/Server Communication component library can be used with Microsoft VBA applications such as EXCEL, ACCESS, and Microsoft Office.
Start EXCEL (or other 32-bit Office VBA program such as WORD or ACCESS), then enter design mode. Enable the "Controls Toolbox", choose "Tools" on the menu bar, then "Customize", and then check "Control Toolbox". From the control toolbox, choose and position a "Command Button". This will create code that looks like
Private Sub CommandButton1_Click()
End Sub
Replace the generated code with MODULE32.BAS. The easiest way to do this is to paste from the clipboard. Edit the 'HostName' in this code, using the name of the computer (or IP address in dotted decimal notation) where the server application (see SERVER.VBP) is running.
Exit design mode and then press the command button to start the CSC VBA example program.
CSC can also be used with 32 bit Power Builder applications. See PBUILDER.TXT in the \APPs subdirectory for more information.
CSC32.PBI : Power Builder declaration file.
CSC4VB is thread safe, and can be used from any Windows application capable of using threads.
The "AddressOf" operator, which was added to Visual Basic beginning in version 5.0, is required in order to create and run a Win32 thread in Visual Basic.
Copy CSC32.BAS (if running VB_4.0 /5/6), or CSC32.VB (if running VB.Net) into the same directory (folder) as the application program to which you want to add CSC code. You will find these files in the APPS sub-directory (folder) created when you ran SETUP, usually C:\CSC4VB\APPS.
Open your existing project with "File", "Open Project". Then choose "Insert", "Module", then add CSC32.BAS and KEYCODE.BAS to your project. If prompted to add "DAO 2.50 Object Library", choose "no".
CSC functions can now be called from your VB program.
Open your existing project with "File", "Open Project". Then choose "Project", "Add Module", then add CSC32.VB and KEYCODE.VB to your project. CSC functions can now be called from your VB.NET program.
A description of the protocol used by the example programs can be found in Section_2.7, "Example Protocol", in the CSC User's Manual (http://www.marshallsoft.com/csc_usr.htm#Section_2.7).
Also refer to PROTOCOL.TXT in the \APPS subdirectory.
The error message text associated with CSC error codes can be displayed by calling cscErrorText.
void DisplayError(int ErrCode, char *MsgPtr)
{int Len;
char ErrBuff[129];
printf("ERROR %d: ", ErrCode);
if(MsgPtr) printf("%s: ", MsgPtr);
Len = cscErrorText(ErrCode, (char *)ErrBuff, 128);
if(Len>0) printf("%s\n", ErrBuff);
else printf("\n");
}
The Client/Server Communication Library for Visual Basic supports and has been tested with all versions of Microsoft Visual Basic (VB 4, VB 5, VB 6 and VB.NET).
The Client/Server Communication component library (CSC32.DLL) is written in standard ANSI C (CSC32.C), and has been compiled using Microsoft Visual C/C++ with the STDCALL and DECLSPEC compiler keywords. Source code for the CSC library is provided in the registered version (if ordered) only.
For more information on the C/C++ version of CSC, download the latest version of CSC4C from our web site at http://www.marshallsoft.com/csc4c.htm
Visual Basic project files (.VBP) are provided for all example VB 4/5/6 programs.
Visual Basic NET project files (.VBPROJ) are provided for the VB.Net example programs.
When an application program runs that makes calls to CSC32.DLL, the Windows operating system will locate CSC32.DLL by searching the directories as specified by the Windows search path. If the CSC32.DLL is placed in the \WINDOWS directory (or \WINNT for Windows NT/2000), it will always be found by Windows.
CSC32.DLL can be loaded from an explicit location by replacing "CSC32.DLL" in CSC32.BAS or CSC32.VB by the full path. For example, to load CSC32.DLL from C:\CSC4VB\APPS, the first entry in would be:
Declare Function cscAcceptConnect Lib "C:\CSC4VB\APPS\CSC32.DLL" (ByVal vSock As Long) As Long
The example programs are designed to demonstrate the various capabilities of CSC4VB. The best way to become familiar with CSC4VB is to study and run the example programs.
The example programs can be compiled with the version of Visual Basic indicated below. All example programs are located in the \APPS sub-directory.
The CSCVER ("CSC Version") example program displays the CSC version number. This is the first program to compile and build since it verifies that CSC32.DLL is installed properly.
The project files are CSCVER.VBP for VB_4.0 and above and CSCVER.VBPROJ for VB.Net.
CLIENT is a VB example program that operates as a client that connects to the example server programs.
The project files are CLIENT.VBP for VB_4.0 and above and CLIENT.VBPROJ for VB.Net.
SERVER is a VB example program that operates as a server that accepts connections from the example client program (CLIENT).
SERVER accepts a maximum of 3 connections (clients) at any one time.
The project files are SERVER.VBP for VB_4.0 and above and SERVER.VBPROJ for VB.Net.
FILEGET is a VB example program that operates as a server, and receives files from the FilePut client.
The project file is FILEGET.VBP for VB_4.0 and above.
FILEPUT is a VB example program that operates as a client, and transmits files to the FileGet server.
The project file is FILEPUT.VBP for VB_4.0 and above.
AUTH_C is a VB example program that operates as a client implementing authenticated (challenge/response) connections.
The project file is AUTH_C.VBP for VB_4.0 and above.
AUTH_S is a VB example program that operates as a server implementing authenticated (challenge/response) connections.
The project file is AUTH_S.VBP for VB_4.0 and above.
The FileSrv example server program can accept multiple connections and allows clients to download files. See the comments in FileSrv.frm or see PROTOCOL.TXT for a description of the protocol used.
The project file is FileSrv.VBP for VB_4.0 and above.
The FileCli example client program connects to the FileSrv example server program in order to download files. See the comments in FileCli.frm or see PROTOCOL.TXT for a description of the protocol used.
The project file is FileCli.VBP for VB_4.0 and above.
HELLO is an example program that demonstrates the use of the CSC class cscClass.cls.
The project file is HELLO.VBP for VB_5.0 and above.
Download is an example client that connects to the MarshallSoft web site (HTTP server) and downloads a file from the ./files directory.
The project file is Download.VBP for VB_4.0 and above.
Version 2.0
The first Visual Basic version of CSC.
Version 3.0: September 9, 2005.
Version 4.0: April 11, 2007