ST101WinSock.dll

Version 1.4, Released January 28, 2004
Copyright (c) 2002-2004 by Segue Corporation. All rights reserved.

This file describes ST101WinSock.dll. It contains a set of optimized socket routines that allow you to call the Winsock API directly from eMbedded Visual Basic and eMbedded Visual C++. These routines are meant to replace the WinSock ActiveX control that comes with eVB with the following advantages.

You can download the free personal version or purchase a commercial version of the software at http://www.SegueMD.com/winsock.

We can help you develop that wireless or socket-based application on your Pocket PC. We provide online training, technical support, and consulting for Windows CE, Palm OS, Internet Technologies, and the Oracle Relational Database.


Table of Contents


License

Personal Version

Commercial Version

Software License


Installation

The software is compatible under Windows CE 3.0, and Pocket PC 2002 using the Palm-Sized PC, Handheld PC Pro, or Pocket PC. Select the correct DLL for your platform (MIPS, SH3, StrongArm, Emulator), and copy it to the \Windows directory on your Pocket PC.


Winsock Programming Tips

The purpose of this help file is to describe the functions provided. If you need help to learn how to program sockets under Windows CE, please check out the WinSock Programmer's FAQ. If you need additional help, we provide training, consulting, and programming support for an additional fee.

Binary Data Transfer

Because of the conversion between Visual Basic and Visual C++, all data is transferred in wide character strings. Look under ST101_Send and ST101_Recv for information on how to send and receive strings of binary data.

IP Address Resolution

The Pocket PC 2002 cannot resolve IP addresses unless the device is connected to a WINS server or has a host entry in its registry. This is not true for C/C++ programs under Windows CE 3.0, Windows 98, and Windows 2000. In addition, this is not true when using the WinSock Active X control under eVB. So as far as I can tell, this is a bug feature. It is documented at  http://www.microsoft.com/mobile/pocketpc/tips/activesyncnet.asp. Microsoft recommends that you can download Pocket Hosts from Marc Zimmerman's site to create host entries in your registry.

Microsoft Pocket PC Connection Wizard

If your Pocket PC isn't configured for TCP/IP, you may need to download and run the Microsoft Pocket PC Connection Wizard. This wizard will run on your desktop and will help you set up your Pocket PC to accept a variety of connection options.


Client Functions

A simple client program would use the following functions.

Public Sub SimpleClient()
    Dim iRet As Integer
    Dim buf As String
    Dim iSocket as Integer

    'Connect
    iRet = ST101_WSAStartup
    iSocket = ST101_Socket(AF_INET, SOCK_STREAM, 0)
    iRet = ST101_Connect(iSocket, "192.168.1.101", 23, "LICENSE")

    'Send data
    iRet = ST101_Send(iSocket, "Hello, world!", Len("Hello, world!"))

    'Read data, if any is waiting
    iRet = ST101_DataWaiting(iSocket)
    If iRet > 0 Then
        buf = Space(iRet)
        iRet = ST101_Recv(iSocket, buf, iRet)
    End If

    'Clean up
    iRet = ST101_closesocket(iSocket)
    iRet = ST101_WSACleanup()
End Sub


Server Functions

A simple server program would use the following functions.

Public Sub SimpleServer()
    Dim iRet As Integer
    Dim localSocket, inputSocket As Integer
    Dim buf As String

    'Get into listening mode
    iRet = ST101_WSAStartup
    localSocket = ST101_Socket(AF_INET, SOCK_STREAM, 0)
    iRet = ST101_Bind(localSocket , 23)
    iRet = ST101_Listen(localSocket , 1, "LICENSE")

    'Make a connection
    inputSocket = ST101_AcceptTimeOut(iSocket, 20)
    If iRet < 0 Then Exit Sub

    'Send data
    iRet = ST101_Send(iSocket, "Hello, world!", Len("Hello, world!"))

    'Read data, if any is waiting
    iRet = ST101_DataWaiting(inputSocket)
    If iRet > 0 Then
        buf = Space(iRet)
        iRet = ST101_Recv(inputSocket, buf, iRet)
    End If

    'Clean up
    iRet = ST101_ShutDown(inputSocket)
    iRet = ST101_CloseSocket(inputSocket)
    iRet = ST101_CloseSocket(localSocket)
    iRet = ST101_WSACleanup()
End Sub


Alphabetical List of Functions and Constants


Constants

Note that these must be Private constants if they are declared in a form (*.ebf file). They may be Public constants if declared in a module (*.bas file).


ST101_Accept

Description

Declaration

Arguments


ST101_AcceptTimeOut

Description

Declaration

Arguments


ST101_Bind

Description

Declaration

Arguments


ST101_CloseSocket

Description

Declaration

Arguments


ST101_Connect

Description

Declaration

Arguments


ST101_ConnectTimeOut

Description

Declaration

Arguments


ST101_DataWaiting

Description

Declaration

Arguments


ST101_GetDLLVersion

Description

Declaration

Arguments


ST101_GetHostName

Description

Declaration

Arguments


ST101_GetHostNameFromIP

Description

Declaration

Arguments


ST101_GetIPFromHostName

Description

Declaration

Arguments


ST101_Listen

Description

Declaration

Arguments


ST101_Recv

Description

Declaration

Arguments


ST101_RecvTimeOut

Description

Declaration

Arguments


ST101_Send

Description

Declaration

Arguments


ST101_SendTimeOut

Description

Declaration

Arguments


ST101_SetSockOpt_Tcp_NoDelay

Description

Declaration

Arguments


ST101_Shutdown

Description

Declaration

Arguments


ST101_Socket

Description

Declaration

Arguments


ST101_WSACleanup

Description

Declaration

Arguments


ST101_WSAGetLastError

Description

Declaration

Arguments


ST101_WSAStartup

Description

Declaration

Arguments


Declarations for eVB

To make it easier to use ST101WinSock with eVB, all declarations and constants are included below. Copy and paste this information into an eVB module (*.bas file).

Public Const AF_INET = 2
Public Const AF_IRDA = 22
Public Const SOCK_STREAM = 1
Public Const SOCK_DGRAM = 2
Public Const INVALID_SOCKET = -1
Public Const SOCKET_ERROR = -1

Declare Function ST101_Accept Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal license As String) As Integer
Declare Function ST101_AcceptTimeOut Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal sec As Integer, ByVal license As String) As Integer
Declare Function ST101_Bind Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal port As Integer) As Integer
Declare Function ST101_CloseSocket Lib "ST101WinSock.dll" (ByVal iSocket As Integer) As Integer
Declare Function ST101_Connect Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal addr As String, ByVal port As Integer, ByVal license As String) As Integer
Declare Function ST101_ConnectTimeOut Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal addr As String, ByVal port As Integer, ByVal sec As Integer, ByVal license As String) As Integer
Declare Function ST101_DataWaiting Lib "ST101WinSock.dll" (ByVal iSocket As Integer) As Integer
Declare Function ST101_GetDLLVersion Lib "ST101WinSock.dll" () As String
Declare Function ST101_GetHostName Lib "ST101WinSock.dll" () As String
Declare Function ST101_GetHostNameFromIP Lib "ST101WinSock.dll" (ByVal addr As String) As String
Declare Function ST101_GetIPFromHostName Lib "ST101WinSock.dll" (ByVal addr As String) As String
Declare Function ST101_Listen Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal backlog As Integer, ByVal license As String) As Integer
Declare Function ST101_Recv Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal buf As String, ByVal buflen As Integer) As Integer
Declare Function ST101_RecvTimeOut Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal buf As String, ByVal buflen As Integer, ByVal sec As Integer) As Integer
Declare Function ST101_Send Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal buf As String, ByVal buflen As Integer) As Integer
Declare Function ST101_SendTimeOut Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal buf As String, ByVal buflen As Integer, ByVal sec As Integer) As Integer
Declare Function ST101_SetSockOpt_Tcp_NoDelay Lib "ST101WinSock.dll" (ByVal iSocket As Integer, ByVal opt As Integer) As Integer
Declare Function ST101_Shutdown Lib "ST101WinSock.dll" (ByVal iSocket As Integer) As Integer
Declare Function ST101_Socket Lib "ST101WinSock.dll" (ByVal af As Integer, ByVal itype As Integer, ByVal protocol As Integer) As Integer
Declare Function ST101_WSACleanup Lib "ST101WinSock.dll" () As Integer
Declare Function ST101_WSAGetLastError Lib "ST101WinSock.dll" () As Integer
Declare Function ST101_WSAStartup Lib "ST101WinSock.dll" () As Integer


Declarations for eVC++

The ST101WinSock DLL can be called from an eVC++ program. The include file information for this purpose is shown below.

#define MYDLL_IMPLEMENTATION

#ifdef MYDLL_IMPLEMENTATION
#define DLLEXPORT _declspec(dllexport)
#else
#define DLLEXPORT _declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C" {
#endif

DLLEXPORT int _cdecl ST101_WSAStartup (void);
DLLEXPORT int _cdecl ST101_WSACleanup (void);
DLLEXPORT SOCKET _cdecl ST101_Socket (int af, int itype, int protocol);
DLLEXPORT int _cdecl ST101_Connect (SOCKET s, TCHAR *host_address, int port_number, TCHAR *szLicense);
DLLEXPORT int _cdecl ST101_ConnectTimeOut (SOCKET s, TCHAR *host_address, int port_number, int timeOut, TCHAR *szLicense);
DLLEXPORT int _cdecl ST101_Bind (SOCKET s, int port_number);
DLLEXPORT int _cdecl ST101_Listen (SOCKET s, int backlog);
DLLEXPORT int _cdecl ST101_Accept (SOCKET s, TCHAR *szLicense);
DLLEXPORT int _cdecl ST101_AcceptTimeOut (SOCKET s, int timeOut, TCHAR *szLicense);

DLLEXPORT int _cdecl ST101_Send (SOCKET s, TCHAR *buf, int buflen);
DLLEXPORT int _cdecl ST101_SendTimeOut (SOCKET s, TCHAR *buf, int buflen, int timeOut);
DLLEXPORT int _cdecl ST101_Recv (SOCKET s, TCHAR *buf, int buflen);
DLLEXPORT int _cdecl ST101_RecvTimeOut (SOCKET s, TCHAR *buf, int buflen, int timeOut);
DLLEXPORT int _cdecl ST101_SetRecvTimeOut (SOCKET s, int timeOut);
DLLEXPORT int _cdecl ST101_SetSendTimeOut (SOCKET s, int timeOut);
DLLEXPORT int _cdecl ST101_CloseSocket (SOCKET s);
DLLEXPORT int _cdecl ST101_Shutdown (SOCKET s);
DLLEXPORT int _cdecl ST101_DataWaiting (SOCKET s);

DLLEXPORT int _cdecl ST101_SetSockOpt_Tcp_NoDelay (SOCKET s, int val);
DLLEXPORT int _cdecl ST101_SetSockOpt_Linger (SOCKET s, int val);
DLLEXPORT int _cdecl ST101_SetSockOpt_DontLinger (SOCKET s);
DLLEXPORT int _cdecl ST101_WSAGetLastError (void);
DLLEXPORT void _cdecl ST101_WSASetLastError (int val);
DLLEXPORT TCHAR * _cdecl ST101_GetHostNameFromIP (TCHAR *host_address);
DLLEXPORT TCHAR * _cdecl ST101_GetIPFromHostName (TCHAR *host_address);
DLLEXPORT TCHAR * _cdecl ST101_GetHostName (void);
DLLEXPORT TCHAR * _cdecl ST101_GetDLLVersion(void);

void checkLicense(TCHAR *szLicense);
void displayLicense(void);

#ifdef __cplusplus
}
#endif