VC和VB数据类型对比

来源:互联网 发布:淘宝联盟频道推广 编辑:程序博客网 时间:2024/04/30 18:16
VC和VB数据类型对比

API形式

VC

VB

长度

char

Byte

1 byte

unsignedchar;BYTE

Byte

1 byte

signed char

Byte

1 byte

short

Integer

2 bytes

unsigned short;WORD

Integer

2 bytes

int;BOOL;INT

Long

4 bytes

unsigned int;UINT;WPARAM

Long

4 bytes

long;LPARAM;DWORD

Long

4 bytes

float;FLOAT

Single

4 bytes

double

Double

8 bytes

long double

Double

8 bytes

 

COM形式

 Platform SDK: COM

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 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.

Note

  Future versions of Visual Basic, version 6.0 and beyond, will support structures.

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. For more information about Automation data types, see the Automation documentation in the Platform SDK.

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 typeVARTYPE equivalentInteger16 bit, signed, VT_I2Long32 bit, signed, VT_I4DateVT_DATECurrencyVT_CYObject*VT_DISPATCHStringVT_BSTRBooleanVT_BOOLCurrencyVT_DECIMALSingleVT_R4DoubleVT_R8DecimalVT_DECIMALByteVT_DECIMALVariantVT_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.

0 0
原创粉丝点击