Skip to main content
Add sample code
Source Link
Laurent Etiemble
  • 28.1k
  • 5
  • 59
  • 81

It seems that there is size problem between your data (23 bytes) and the size of structure (24 bytes). Is it normal ?

Update: The Pack=1 attribute should guarantee the memory alignment, but googling gives divergent response on structure's field alignment . What you can do is to read 23 bytes in a byte array, then extract the two strings with the Encoding class:

byte[] array = ... // read 23 bytes
String s1 = Encoding.ASCII.GetString(array, 0, 19);
String s2 = Encoding.ASCII.GetString(array, 19, 4); 

It seems that there is size problem between your data (23 bytes) and the size of structure (24 bytes). Is it normal ?

It seems that there is size problem between your data (23 bytes) and the size of structure (24 bytes). Is it normal ?

Update: The Pack=1 attribute should guarantee the memory alignment, but googling gives divergent response on structure's field alignment . What you can do is to read 23 bytes in a byte array, then extract the two strings with the Encoding class:

byte[] array = ... // read 23 bytes
String s1 = Encoding.ASCII.GetString(array, 0, 19);
String s2 = Encoding.ASCII.GetString(array, 19, 4); 
Source Link
Laurent Etiemble
  • 28.1k
  • 5
  • 59
  • 81

It seems that there is size problem between your data (23 bytes) and the size of structure (24 bytes). Is it normal ?