struct File IO

  • Thread starter Thread starter Sunny
  • Start date Start date
S

Sunny

Hi everyone,

I want to write a structure variable to file, in eVC++ for this purpose
fread/fwrite is used.
Using C# on desktop it is possible to do so using "BinaryFormatter" class
not present in CF.
On internet i also came across few thiry party framework to this in CF.

Can't we do so without thiry partry framework?

-Sunny
 
For a true struct it's quite simple (not the case for a class):

private unsafe void WriteStruct(MyStruct ms, FileStream fs)
{
byte[] data = new byte[sizeof(MyStruct)];
Marshal.Copy(new IntPtr(&ms), data, 0, data.Length);
fs.Write(data, 0, data.Length);
}

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
Back
Top