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