i have a struct with dynamic length:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct PktAck
{
public Int32 code;
[MarshalAs(UnmanagedType.LPStr)]
public string text;
}
when i'm converting bytes[] to struct by this code:
GCHandle handle = GCHandle.Alloc(bytes_array, GCHandleType.Pinned);
result_struct = (PktAck)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PktAck));
handle.Free();
i have a error, because size of struct less than size of bytes[] and "string text" is pointer to string...
how can i use dynamic strings? or i can use only something like this:
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1000)]
upd: c struct
struct PktAck
{
int code;
char* text;
}