Data Types  
 

Because various languages handle data types in different ways, the SocketTools components have been designed to use variants. A variant is a special data type which can be used to represent multiple types of data, including integer, string, date and currency values. All of the SocketTools methods and events use variant types and the developer is responsible for converting those variants into the required data type. For example, in Visual C++, this can be accomplished using the CComVariant class.

In addition to variant types, the controls also use numeric data types for many property values. The following is a list of numeric data types that are used, along with their C and Visual Basic equivalents.

Description Size Range C / C++ VB 6 VB.NET
Byte 1 byte 0 to 255 BYTE Byte Byte
Boolean 4 bytes 0 is False, 1 is True BOOL Long Integer
Integer 4 bytes -2,147,483,648 to 2,147,483,647 INT Long Integer
Integer 4 bytes 0 to 4,294,967,295 UINT Long Integer
Short Integer 2 bytes -32,768 to 32,767 SHORT Integer Short
Short Integer 2 bytes 0 to 65,535 WORD Integer Short
Long Integer 4 bytes -2,147,483,648 to 2,147,483,647 LONG Long Integer
Long Integer 4 bytes 0 to 4,294,967,295 DWORD Long Integer

One problem that is frequently encountered when converting function definitions from C or C++ to other languages is the size of the integer data type. For example, default integer size for Visual Basic 6 is 16-bits on 32-bit platforms. However, in Visual Basic.NET, as well as languages like Visual C++, the default integer size is 32-bits. Also, some languages do not support unsigned integer types. In this case, as with Visual Basic, the signed type should be used instead.

Boolean Data

Boolean parameters present a special problem for two reasons. Firstly, the data types used to represent boolean values frequently vary between languages. Secondly, different languages represent the values "true" and "false" differently. In languages like Visual C++, boolean parameters should always be passed as 32-bit signed integers.

String Data

String arguments can also present a problem when calling methods from languages such as Visual C++. All strings, regardless of whether they are assigned to property values or to be passed as arguments, must be specified as BSTRs. A BSTR is essentially a null-terminated Unicode string with the length of the string prepended to it. Each character in the BSTR is represented as a 16-bit value. With languages such as Visual Basic, strings are handled transparently. However, in C++ it is required that those strings be allocated and managed by the application. It is recommended that you use classes like CComBSTR to represent your string values.

If you are unsure of how your language handles BSTRs, we recommend that you review the language's technical reference for information on how to assign string values to the property of a COM object, or when calling a method. If your language supports COM interfaces, it will typically either handle BSTR strings transparently or provide a collection of functions which can be used to create, modify and delete them.