Hi Robert,
i think, you are looking for this (PInvoke Style):
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)
public struct rec
{
[MarshalAs(UnmanagedType.LPStr,SizeConst=1)]
string index; //could also be a byte
[MarshalAs(UnmanagedType.LPStr,SizeConst=50)]
string padding;//could also be a byte
[MarshalAs(UnmanagedType.LPStr,SizeConst=28)]
string name;//could also be a byte
}
then you go like this:
rec your_rec = (rec)
Marshal.PtrToStructure(ptrPointerToYourBytesBlockOfMemory,typeof(rec));
MessageBox.Show(your_rec.name);
Regards
Kerem
--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project:
http://www.codeplex.com/restarts
Latest Open-Source Projects:
http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
"robert.waters" <(E-Mail Removed)> schrieb im Newsbeitrag
news:9b88c175-3ba3-4339-8957-(E-Mail Removed)...
>I have to parse a binary file having a number of fixed records, each
> record containing datas in fixed positions. I would like to parse
> this binary file into an array of structures having members that
> represent those fields, so that I can access the records in a
> meaningful way.
> Using C, I would have defined a struct that I could cast a byte array
> into, which held exactly one of these fixed records. The struct would
> be defined as such:
> struct rec {
> char index[1] ;
> char padding[50];
> char name[28];
> };
> No big deal, (rec)char_array;.
>
> I tried to do something similar in C#, and I am getting an error
> telling me that:
> "Array size cannot be specified in a variable declaration"
>
> How might I create a data structure with fixed-size members at design
> time?
> Do I really have to encapsulate this into a class that contains logic
> to parse the record sequentially when it's instantiated?
>
> Thanks.