Reading binary data into structure

Hi all,

I’m restarting programming with Xojo and new in this forum (coming from Real Studio background some years ago).
Programming is not new to me (background in Pascal, Assembly, C, Perl, PHP and MySQL) and recently Cocoa.
My problem is this:

I have a file with binary data and the first 50 bytes of that file are headerinformation about what the rest of that file is about.
This header contains fields of bytelength, wordlength, pointers as well as strings.
I have set up a structure that represents the format of this header and was trying to read the information from the file into this structure with the BinaryStream method.
So I have this:

Dim myFile As FolderItem Dim ms As MyStructure Dim b As BinaryStream b = BinaryStream.Open(myFile) ms = b.Read(50)
At that point I get an error: Type Mismatch because the Read function returns a String.
I was hoping for a function that could read any number of bytes (all at once) into my structure without any type checking done. Is that possible?
Setting up a loop and reading one byte at a time is no problem but seems slow on long headers.


ms.StringValue = b.Read(50)

or something similar…

Look at the Structure.StringValue method.

ms.StringValue( endiness ) = b.Read( 50 )

Just what I needed! Thanks.