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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top