Translating to Visual Basic from C++

Using the C++ programming language, developers can directly access the memory that stores a particular variable. Memory pointers provide this direct access. In Visual Basic, pointers are handled for you. For example, a parameter declared as a pointer to an int in C++ is equivalent to a parameter declared in Visual Basic as a ByRef Integer.

A parameter that is declared As String in Visual Basic is declared as a pointer to a BSTR in C++. Setting a string pointer to NULL in C++ is equivalent to setting the string to the vbNullString constant in Visual Basic. Passing in a zero-length string ("") to a function designed to receive NULL does not work, as this passes a pointer to a zero-length string instead of a zero pointer.

C++ supports data containers, namely structures and unions, that have no equivalent in early versions of Visual Basic. For this reason, COM objects typically wrap information that usually is stored in structures and unions in object classes. Some COM objects, however, may contain structures, causing portions of the object's methods or functionality to be inaccessible to Visual Basic.

Some C++ data types are not supported in Visual Basic, for example unsigned types and HWND types. Methods that accept or return these data types are not available in Visual Basic.

Visual Basic uses Automation-compatible data types as its internal data types. Thus, C++ data types that are Automation-compatible are also compatible with Visual Basic. Data types that are not Automation-compatible may not be able to be converted to Visual Basic.

The following table lists the data types are supported by Visual Basic and their VARTYPE equivalents. VARTYPE is an enumeration that lists the Automation variant types.

Visual Basic data type VARTYPE equivalent
Integer
16 bit, signed, VT_I2
Long
32 bit, signed, VT_I4
Date
VT_DATE
Currency
VT_CY
Object
*VT_DISPATCH
String
VT_BSTR
Boolean
VT_BOOL
Currency
VT_DECIMAL
Single
VT_R4
Double
VT_R8
Decimal
VT_DECIMAL
Byte
VT_DECIMAL
Variant
VT_VARIANT

All parameters in Visual Basic, unless labeled with the keyword ByVal, are passed by reference (as pointers) instead of by value.

C++ and Visual Basic differ slightly in how they represent properties. In C++, properties are represented as a set of accessor functions, one that sets the property value and one that retrieves the property value. In Visual Basic, properties are represented as a single item that can be used to retrieve or set the property value.

Translating to Visual Basic