I have this struct in my C++ app:
struct textField
{
//0
union nameField
{
void* ptr;
char cstring[16];
} text;
//16
uint8_t textLength;
//17
char unknown1[3];
//20
uint8_t fieldType;
//21
char unknown2[3];
//24
uint32_t unknown3;
//28
};
And I know that in VB6, it will look something like this:
Private Type textField ' 0
cstring(0 To 15) As Byte ' 16
textLength As Byte ' 17
unknown1(0 To 2) As Byte ' 20
fieldType As Byte ' 21
unknown2(0 To 2) As Byte ' 24
unknown3 As Long ' 28
End Type
But what about the union in the struct? How can it be accomplished?
The easiest way is to use the variant type - this can contain any other type.
Note that there probably is no direct mapping of void *
into VB so you will need to study how the union is used rather than just a quick conversion.
Use the LSET
command.
It's not declared in line with the struct, but rather thereafter upon declaring an instance of the object.
Example :
Private Type MyType1
x as Integer
y as Integer
z as Integer
w as Integer
End Type
Private Type MyType2
a as Long
b as Long
End Type
Private Sub Form_Load()
Dim t1 as MyType1
Dim t2 as MyType2
t1.x = 0
t1.y = 0
t1.z = -1
t1.w = -1
LSet t2 = t1
....
This has the same effect as an unnamed union between the two types.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.