I'm not sure what you really want to do. Anyhow here's some hints:
If you want to serialize/deserialize an object, BOTH ACTIONS IN .Net, in a
binary file here's an example:
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace ConsoleApplication2
{
/// <summary>
/// Summary description for Class1.
/// </summary>
[Serializable]
public struct Point
{
private int x, y;
// Constructor:
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public int xValue
{
get {return this.x;}
set {this.x = value;}
}
public int yValue
{
get {return this.y;}
set {this.y = value;}
}
// Override the ToString method:
public override string ToString()
{
return(String.Format("(x,y)= " + x + "," + y));
}
}
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Point p = new Point(10,15);
Console.WriteLine(p.ToString());
p.xValue = 3;
p.yValue = 4;
Console.WriteLine(p.ToString());
FileStream fs = new FileStream("d:/kk.bin",FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs,p);
fs.Close();
p.xValue = 12;
p.yValue = 13;
Console.WriteLine(p.ToString());
fs = new FileStream("d:/kk.bin",FileMode.Open);
p = (Point)(formatter.Deserialize(fs));
Console.WriteLine(p.ToString());
Console.ReadLine();
}
}
}
That eases your effort, but it can't be deserialized in other environments.
If you want to have compatibility with all other environments you can use
the sequence of code I've already gived you; it works both ways, the byte[]
buffer can be read/write through a Stream from/to a file.
--
Horatiu Ripa
"Cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
How would you do the same to write the entire structure to a random
access file (so using a C filesystem call as there is no api call in
.net to write directly a structure content) ?
Thanks,
Cybertof.
In article <uw**************@TK2MSFTNGP10.phx.gbl>, un****@businessco.us
says...Console.WriteLine(p->integerValue);
Console.WriteLine(p->charValue);