|
-
Dec 11th, 2002, 11:09 AM
#1
Thread Starter
New Member
fixed array in a structure
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
Type WSAData
A(100) As Byte
B As Integer
End Type
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.
Is there any way arround this?
thanks
-
Dec 11th, 2002, 12:14 PM
#2
Sleep mode
Ok I've tried your code but gives this msg :
Arrays declared as structure members cannot be declared with an initial sizeSee Also
Arrays | Structure Declaration
An array in a structure is declared with an initial size.
To correct this error
Define arrays in structures as dynamic.
You can re-dimension dynamic arrays with if a fixed-size array is required. For example:
VB Code:
Structure MyStruct
Public MyArray() 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
according to MS.
-
Dec 11th, 2002, 01:08 PM
#3
Thread Starter
New Member
Thanks, but thats no use. Thats a dynamic array where I need a static fixed array.. the problem is thus:
VB Code:
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
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
VB Code:
Type MyStruct
MyArray(9) As Integer
MyInt As Integer
End Type
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.
Thanks for any more help on this
-
Dec 11th, 2002, 03:44 PM
#4
Sleep mode
If I'm not wrong , you're trying to create new user-data type.Well,I've never faced such this stuff.
-
Feb 12th, 2003, 05:33 PM
#5
Member
I know this is a little old, but:
Structure Whatever
<vbfixedarray (15)> public ArrayName as Integer
End Structure
Defines a fixed array of 16 integers.
For strings, use
<vbfixedstring(15)> public StringName as String
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|