-
Marshal arrays of strings - how to?
I have problem with accessing arrays of strings.
Below is a VB.NET code of function StructToByteArray, which is modified version of http://www.codeproject.com/useritems...stobinfile.asp
'This function copys the structure data into a byte()
Private Function StructToByteArray(ByVal strukt As Object) As Byte()
Try
Dim buffer(Marshal.SizeOf(strukt)) As Byte
'Allocate the buffer to memory and pin it so that GC cannot use the space (Disable GC)
Dim h As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
'copy the struct into int byte() mem alloc
Marshal.StructureToPtr(strukt, h.AddrOfPinnedObject(), False)
h.Free() 'Allow GC to do its job
Return buffer ' return the byte(). After all thats why we are here right.
Catch ex As Exception
BladPokaz(ex)
Return Nothing
End Try
End Function
And here are the sample structure:
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Private Structure Str1
Friend dintVal As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=10)> _
Friend dintArr() As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=6)> _
Friend stringVal As String
End Structure
What we've got here is Integer value, array of Integer values and a String value.
The problem is how to define an array of Strings. The size of array
and size of String could be fixed.
I've tried other array types (SafeArray, ByValTStr, etc.) and define ArraySubType.
None of this worked for me.
Thanks in advance for your help.
Marc
Similar Threads
-
By Miha Markic in forum .NET
Replies: 5
Last Post: 06-19-2006, 09:48 AM
-
By Mark Alexander Bertenshaw in forum VB Classic
Replies: 4
Last Post: 03-04-2002, 08:04 AM
-
Replies: 15
Last Post: 05-09-2001, 04:40 AM
-
By Brian Leung in forum VB Classic
Replies: 12
Last Post: 06-20-2000, 03:06 PM
-
By Brian Leung in forum VB Classic
Replies: 0
Last Post: 06-20-2000, 09:47 AM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|