Client / Server Communications
for Visual Basic
Programmer's Manual
(CSC_4VB)
Version 6.0
July 24. 2009
This software is provided as-is.
There are no warranties, expressed or implied.
Copyright (C) 2009
All rights reserved
MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815
Voice : 1.256.881.4630
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 Win32 STDCALL and DECLSPEC
2.3 Dynamic Strings
2.4 CSC4VB Class
2.5 Visual Studio .Net
2.6 Visual Basic for Applications (VBA)
2.7 PowerBuilder
2.8 Using Threads
2.9 Adding CSC to a Project
2.10 Error Display
2.11 Example Client/Server Protocol
3.1 Compiling CSC4 Example Programs
3.2 Compiling Example Programs
3.3 Explicitly Loading a CSC 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
4.12 GetPrice
4.13 uNetTime
The Client / Server Communications Library for Visual Basic (CSC4VB) is a toolkit that allows software developers to quickly develop server and client TCP/IP and UDP applications in Visual Basic or Visual Basic .NET.
The Client / Server Communications Library (CSC) is a component library that uses the Windows API to create client and server programs (Win32 and Win64) that can communicate with each other across any TCP or UDP network such as the Internet or a private network (intranet or LAN [local area net]).
CSC can 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.
The Client / Server Communications Library for Visual Basic (CSC4VB) component library supports and has been tested with all versions of Microsoft Visual Basic including Visual Basic .NET and Visual Studio. All programs will compile using VB-4.0 through VB-6.0 or Visual Studio.
CSC4VB includes multiple Visual Basic example programs demonstrating client/server protocols, including examples that connect to HTTP (web) and POP3 servers as well as encrypt files.
Both Win32 DLL and Win64 DLL are provided. CSC4VB runs under all versions of Windows (95/98/ME/2000/2003/NT/XP/Vista/x64). The Client / Server Communications Library SDK DLLs (CSC32.DLL and CSC64.DLL) can also be used from any language (Visual C++, .NET, ACCESS, EXCEL, VBA, 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:
MarshallSoft also has versions of the Client/Server Communications Library for C/C++ (CSC4C), Delphi (CSC4D), and Visual FoxPro (CSC4FP). All versions of the CSC library use the same DLLs (CSC32.DLL and CSC64.DLL). However, the examples provided for each version are written for the specified programming language.
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:
A good selection of Visual Basic (and Visual Studio .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.
GetPrice Downloads stock price from Yahoo.
uNetTime UDP client gets Network Time.
The complete set of documentation consists of three manuals in two formats. This is the first manual (CSC_4VB) in the set.
The CSC_4VB Programmer's Manual is the language specific (Visual Basic and Visual Studio .Net) manual. All language dependent programming issues are discussed in this manual. Information needed to compile 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 two 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 where CSC4VB was installed.
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 and CSC64.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 USD (or $195 USD with source code [ANSI C] to the library DLL). Purchasing details can be found in Section_1.4, "How to Purchase", of the CSC User's Manual (CSC_USR). (http://www.marshallsoft.com/csc_usr.htm#Section_1.4)
Also see INVOICE.TXT or http://www.marshallsoft.com/order.htm
When a developer license is purchased for CSC, the developer will be sent a registered DLL plus a license file (CSCxxxxx.LIC). The license file can be used to update the registered DLL for a period of one year from purchase. Updates can be downloaded from
http://www.marshallsoft.com/oem.htm
After one year, the developer license must be updated to be able to download updates. The license can be updated for $30 if ordered within one year of the original purchase (or previous update). Between one year and three years, licenses can be updated for $55. After three years, updates are $75. Updates to the source code can be purchased for $40.
Note that the registered CSC DLL does not expire.
CSC32.DLL and CSC64.DLL each have a keycode encoded within it. The keycode is a 9 or 10 digit decimal number (unless it is 0), and will be found in the file KEYCODE.BAS or KEYCODE.VB. The keycode for the evaluation version is 0. The developer will receive a new key code when registering. The KEYCODE is passed to cscAttach.
If an error message (value -74) is returned when calling cscAttach , it means that the keycode in the CSC application does not match the keycode in the DLL. After registering, it is best to remove the evaluation version of CSC32.DLL and CSC64.DLL from the Windows search.
The Client/Server Communications Library for Visual Basic has been tested on multiple computers running Windows 95/98/Me/2003/XP/Vista/Vista x64 and Windows NT/2000.
The CSC4VB library has also been tested with several Visual Basic compilers, from VB_4.0 .0 through VB_6.0 .0 and Visual Studio .Net. CSC can also be used with Power Builder as well as 32-bit or 64-bit VBA applications such as Microsoft Office, EXCEL and ACCESS.
The SETUP installation program will copy the Lib's and DLL to the Windows directory. Refer to Section 1.4 "Installation". After SETUP is run, the CSC4VB files are copied to the directory specified (default \CSC4VB). Three sub-directories are created, as follows:
DOCS - All documentation files
APPS - All example code
DLLS - All DLL's
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 following files can be found in the DLL sub-directory when SETUP is run:
csc32.dll - Win32 version of CSC
csc64.dll - Win64 version of CSC
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. Leading underscores and trailing "@size" strings are not added to function names.
The CSC32.DLL and CSC64.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 and CSC64.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 Visual Studio .Net 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 (CSC64.VB) (if running Visual Studio .Net) into the same directory (folder) as the application program to which CSC code is to be added to. The files can be found in the APPS sub-directory (folder) created when SETUP was run, usually C:\CSC4VB\APPS.
Open the existing project with "File", "Open Project". Then choose "Insert", "Module", then add CSC32.BAS and KEYCODE.BAS to the project. If prompted to add "DAO 2.50 Object Library", choose "no".
CSC functions can now be called from a VB program.
Open the existing project with "File", "Open Project". Then choose "Project", "Add Module", then add CSC32.VB and KEYCODE.VB to the project. CSC functions can now be called from a Visual Studio .Net program.
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");
}
Several of the Client/Server Communications Library demonstration programs use the following example protocol:
"CSC Example Server"
The server responds with the following response strings when presented with the corresponding requests (REQ) from the client:
REQ Response String Request Example Response Example
WHO Sends name of the server. WHO W_SERVER
VER Sends server version #. VER 2.0
BYE OK (then disconnects) BYE OK
ECH Sends string after "ECHO " ECH Hello Hello
The above protocol is just an example. The programmer can create whatever protocol is required. Request strings can be any length, although it is best to keep them as short as possible..
Also refer to PROTOCOL.TXT in the CSC4VB\DOCS subdirectory.
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 Visual Studio .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 Visual Studio .Net example programs.
When an application program runs that makes calls to CSC32.DLL or CSC64.DLL, the Windows operating system will locate CSC32.DLL (CSC642.DLL) by searching the directories as specified by the Windows search path. If the CSC32.DLL (CSC64.DLL) is placed in the \WINDOWS directory (or \WINNT for Windows NT/2000), it will always be found by Windows.
CSC32.DLL or CSC64.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
For Win64, substitute CSC64 for CSC32 in the above.
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 CSC4VB\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 CSC DLL is installed properly. Project files are:
cscver.vp Visual Basic 4/5/6
cscver.vbproj Visual Studio / VB.NET
cscver(VS2008).vbproj Visual Studio 2008 (32-bit)
cscver(VS2008)x64.vbproj Visual Studio 2008 (64-bit)
CLIENT is a VB example program that operates as a client that connects to the example server programs. Project files are:
client.vp Visual Basic 4/5/6
client.vbproj Visual Studio / VB.NET
client(VS2008).vbproj Visual Studio 2008 (32-bit)
client(VS2008)x64.vbproj Visual Studio 2008 (64-bit)
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. Project files are:
server.vp Visual Basic 4/5/6
server.vbproj Visual Studio / VB.NET
server(VS2008).vbproj Visual Studio 2008 (32-bit)
server(VS2008)x64.vbproj Visual Studio 2008 (64-bit)
FILEGET is a VB example program that operates as a server, and receives files from the FilePut client. Files are decrypted when received. Project files are:
FileGet.vp Visual Basic 4/5/6
FileGet.vbproj Visual Studio / VB.NET
FileGet(VS2008).vbproj Visual Studio 2008 (32-bit)
FileGet(VS2008)x64.vbproj Visual Studio 2008 (64-bit)
FILEPUT is a VB example program that operates as a client, and transmits files to the FileGet server. Files are encrypted when transmitted. Project files are:
FilePut.vp Visual Basic 4/5/6
FilePut.vbproj Visual Studio / VB.NET
FilePut(VS2008).vbproj Visual Studio 2008 (32-bit)
FilePut(VS2008)x64.vbproj Visual Studio 2008 (64-bit)
AUTH_C is a VB example program that operates as a client implementing authenticated (challenge/response) connections. Project files are:
Authen_c.vbp Visual Basic 4/5/6
Authen_s.vbp Visual Basic 4/5/6
FileSrv.vp Visual Basic 4/5/6
FileSrv.vbproj Visual Studio / VB.NET
FileSrv(VS2008).vbproj Visual Studio 2008 (32-bit)
FileSrv(VS2008)x64.vbproj Visual Studio 2008 (64-bit)
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. Project files are:
FileCli.vp Visual Basic 4/5/6
FileCli.vbproj Visual Studio / VB.NET
FileCli(VS2008).vbproj Visual Studio 2008 (32-bit)
FileCli(VS2008)x64.vbproj Visual Studio 2008 (64-bit)
HELLO is an example program that demonstrates the use of the CSC class cscClass.cls. . Project files are:
Hello.vbp Visual Basic 5/6 (not VB4)
Download is an example client that connects to the MarshallSoft web site (HTTP server) and downloads a file from the ./files directory. Project files are:
Download.vbp Visual Basic 4/5/6
GetPrice is an example client that demonstrates how to download stock price quotes from Yahoo. Project files are:
GetPrice.vbp Visual Basic 4/5/6
uNetTime is an example UDP client that connects to a Network Time Server (on well known port 37) and gets the network time (seconds since 1 January 1900 GMT) from the server. The default server is
time-A.timefreq.bldrdoc.gov
Project files are:
GetPrice.vbp Visual Basic 4/5/6
Version 2.0: October 15, 2004
Visual Basic version of CSC initial release.
Version 3.0: September 9, 2005.
Version 4.0: April 11, 2007
Version 5.0: October 2, 2008.
Version 6.0: July 24, 2009