468,792 Members | 1,725 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,792 developers. It's quick & easy.

question about binary file access

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

Jul 7 '06 #1
5 1871
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]
- mv*@spam.guard.caspershouse.com

"Bit byte" <fl**@flop.comwrote in message
news:J5********************@bt.com...
If I write data from structures to a binary file in C#, can I read back
the file using "unmanaged" C++ ?

Jul 7 '06 #2
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uO****************@TK2MSFTNGP03.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Bit byte" <fl**@flop.comwrote in message
news:J5********************@bt.com...
>If I write data from structures to a binary file in C#, can I read back
the file using "unmanaged" C++ ?


Jul 7 '06 #3
Bit byte wrote:
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.

--
Hope this helps,
Tom Spink
Jul 7 '06 #4
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


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

Jul 7 '06 #5
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]
- mv*@spam.guard.caspershouse.com

"Greg Young" <dr*******************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:uO****************@TK2MSFTNGP03.phx.gbl...
>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]
- mv*@spam.guard.caspershouse.com

"Bit byte" <fl**@flop.comwrote in message
news:J5********************@bt.com...
>>If I write data from structures to a binary file in C#, can I read back
the file using "unmanaged" C++ ?



Jul 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Yeow | last post: by
12 posts views Thread by uno | last post: by
8 posts views Thread by Alex | last post: by
21 posts views Thread by siroregano | last post: by
2 posts views Thread by Youssef Mesri | last post: by
9 posts views Thread by jbrewer | last post: by
1 post views Thread by CARIGAR | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.