大网数据广告活动
Windows 系统接口

Translating to Visual Basic from C++

· 52CE 我爱测

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.

Related topics

Translating to Visual Basic

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。