[Mono-list] Unterminated string

Dmitry Kostenko bis0n@mail.ru
Sat, 23 Oct 2004 22:08:25 +0300


On Friday 22 October 2004 22:59, Neale.Ferguson@SoftwareAG-USA.com wrote:
> I am trying to write a .Net interface to a system of ours. The system takes
> the following structure:
>
> struct XXXid {
> 	short level;
> 	short size;
> 	char	node[8];
> 	char  user[8];
> 	int	no;
> }
>
> Both user & node a 8 byte character strings padded with blanks and not zero
> terminated. I wanted to code the equivalent as a C# structure. Initially I
> came up with:
>
> private struct XXXId {
>        [FieldOffset (0)]  public  short  level;
>        [FieldOffset (2)]  public  short  size;
>        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=8)]
>        [FieldOffset (4)]  public  string node;
>        [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
>        [FieldOffset (12)] public  string user;
>        [FieldOffset (20)] public  int    pid;
> }
Maybe a better go this way?

[StructLayout(LayoutKind.Sequential)]
struct XXXId {
  public Int16 level;
  public Int16 size;
  public byte[8] node;
  public byte[8] user;
  public Int32 no;
}

Encoding.GetBytes(source,Node 0, XXXId.node, 0, 8);
Encoding.GetBytes(sourceUser, 0, XXXId.user, 0, 8);
>
[Skipped]
> Any suggestions for this novice?
>
> Neale
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list

-- 
Dmitry Kostenko
.NET Developer
Registered Linux User #286813