question about binary file access

B

Bit byte

If I write data from structures to a binary file in C#, can I read back
the file using "unmanaged" C++ ?
 
N

Nicholas Paldino [.NET/C# MVP]

Bit byte,

You could, but you would have to use unmanaged functions through the
P/Invoke layer (specifically, the ReadFile method) and unsafe code (so you
can get a direct pointer to the structure to populate).

Hope this helps.
 
G

Greg Young

I disagree with this. You should be able to write them to a binary file
without issue and read them from your unmanaged C++ ...

Are you thinking the other direction Nicholas? Even then you should be able
to read them without too much of a problem.

Cheers,

Greg Yong

Nicholas Paldino said:
Bit byte,

You could, but you would have to use unmanaged functions through the
P/Invoke layer (specifically, the ReadFile method) and unsafe code (so you
can get a direct pointer to the structure to populate).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Bit byte said:
If I write data from structures to a binary file in C#, can I read back
the file using "unmanaged" C++ ?
 
T

Tom Spink

Bit said:
If I write data from structures to a binary file in C#, can I read back
the file using "unmanaged" C++ ?

Hi Bit byte,

Well of course! Are you having a problem with it? If you're just writing
to a file, then you can open that file with anything that can open files,
and read it.
 
G

Guest

If your structs are managed, not unmanaged, you can serialize them to a byte
array with the BinaryFormatter class and write them to a file. Just as well,
you can read this file back into a byte array and perform the reverse
operation.
Peter
 
N

Nicholas Paldino [.NET/C# MVP]

Greg,

Yes, I was thinking of the other way. It would actually be done in a
surprizingly similar way in unmanaged C++ (same API call, etc, etc);


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greg Young said:
I disagree with this. You should be able to write them to a binary file
without issue and read them from your unmanaged C++ ...

Are you thinking the other direction Nicholas? Even then you should be
able to read them without too much of a problem.

Cheers,

Greg Yong

Nicholas Paldino said:
Bit byte,

You could, but you would have to use unmanaged functions through the
P/Invoke layer (specifically, the ReadFile method) and unsafe code (so
you can get a direct pointer to the structure to populate).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Bit byte said:
If I write data from structures to a binary file in C#, can I read back
the file using "unmanaged" C++ ?
 

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

Top