Re: Writing binary data in managed C++
From: Peter Steele (psteele_at_z-force.com)
Date: 10/01/04
- Next message: CJ Taylor: "Re: Decompiler.NET reverse engineers your CLS compliant code"
- Previous message: Robert Jordan: "Re: Decompiler.NET reverse engineers your CLS compliant code"
- In reply to: Peter Steele: "Writing binary data in managed C++"
- Next in thread: Lord2702: "Re: Writing binary data in managed C++"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Sep 2004 19:25:51 -0700
John, here's what I came up with. Assuming we have a simple struct as
follows:
struct
{
...
} X;
whose members have been initialized in some manner, then the following code
can be used to dump the bytes of this structure:
FileStream* fs = new FileStream("C:\\data.bin", FileMode::Create,
FileAccess::Write);
BinaryWriter* bw = new BinaryWriter(fs);
char* bytes = (char*)&X;
char gcbytes __gc[] = new char __gc[sizeof X];
for (int i = 0; i < sizeof X; i++) gcbytes[i] = bytes[i];
bw->Write(gcbytes);
bw->Flush();
bw->Close();
What I don't like about this solution is that it duplicates the entire
structure. Can the data be output directly without this duplication?
Peter
"Peter Steele" <psteele@z-force.com> wrote in message
news:OvgAPS0pEHA.1688@TK2MSFTNGP10.phx.gbl...
>I have a managed C++ project that contains a simple structure:
>
> struct
> {
> <multiple members>
> } mydata;
>
> I want to write the contents of this structure out to disk retaining the
> exactly binary data without any additional header information, and of
> course be able to later read it back in. What's the best way to accomplish
> this?
>
>
- Next message: CJ Taylor: "Re: Decompiler.NET reverse engineers your CLS compliant code"
- Previous message: Robert Jordan: "Re: Decompiler.NET reverse engineers your CLS compliant code"
- In reply to: Peter Steele: "Writing binary data in managed C++"
- Next in thread: Lord2702: "Re: Writing binary data in managed C++"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|