Hi,
Im looking into VB.net for a project but I have come against a problem. Structures required in some DLLs have arrays of byte such as
[vB]
Type WSAData
A(100) As Byte
B As Integer
End Type
[/vB]
The problem is I cant find out how i can replicate this structure in VB.net since you cant use Type definition but have to use Structure, in which you can only define a reference to a dynamic array.
the problem is thus:
[vB]
Structure MyStruct
Public MyArray() As Integer
Public MyInt As Integer
End Structure
Sub UseStruct()
Dim Struct As MyStruct
ReDim Struct.MyArray(9) Dimension as 10 elements
Struct.MyArray(2) = 777 Use the array.
End Sub
[/vB]
would in fact produce something like the following behind the sceens:
Pointer MyArray (this uses up 4 bytes of data)
Integer MyInt (this uses up 4 bytes of data)
Somewhere else in memory a block of 10 bytes of memory is allocated and the variable MyArray references it
In contrast old style VB code
[vB]
Type MyStruct
MyArray(9) As Integer
MyInt As Integer
End Type
[/vB]
would produce something like the following behind the sceens:
Integer *10 MyArray (this uses up 4*10 bytes of data = 40)
Integer MyInt (this uses up 4 bytes of data)
So as you can see there is a big difference in terms of where the data is stored in memory, and the DLL im interfacing with will only accept the data in the format produced by the Type definition.
Is there any way arround this?
thanks
Tim
Im looking into VB.net for a project but I have come against a problem. Structures required in some DLLs have arrays of byte such as
[vB]
Type WSAData
A(100) As Byte
B As Integer
End Type
[/vB]
The problem is I cant find out how i can replicate this structure in VB.net since you cant use Type definition but have to use Structure, in which you can only define a reference to a dynamic array.
the problem is thus:
[vB]
Structure MyStruct
Public MyArray() As Integer
Public MyInt As Integer
End Structure
Sub UseStruct()
Dim Struct As MyStruct
ReDim Struct.MyArray(9) Dimension as 10 elements
Struct.MyArray(2) = 777 Use the array.
End Sub
[/vB]
would in fact produce something like the following behind the sceens:
Pointer MyArray (this uses up 4 bytes of data)
Integer MyInt (this uses up 4 bytes of data)
Somewhere else in memory a block of 10 bytes of memory is allocated and the variable MyArray references it
In contrast old style VB code
[vB]
Type MyStruct
MyArray(9) As Integer
MyInt As Integer
End Type
[/vB]
would produce something like the following behind the sceens:
Integer *10 MyArray (this uses up 4*10 bytes of data = 40)
Integer MyInt (this uses up 4 bytes of data)
So as you can see there is a big difference in terms of where the data is stored in memory, and the DLL im interfacing with will only accept the data in the format produced by the Type definition.
Is there any way arround this?
thanks
Tim