473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 1994
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
1
by: No Spam | last post by:
Dear Access 2003 Users, Is there any way to launch Terminal Server from Access and pass along the user name that is in a text box? I believe mstsc.exe can be passed an IP address (/v), but can...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
12
by: uno | last post by:
Hello, I am a beginner with the programming and I have some question. I am reading manuals from Internet and some book from the library. In all those documents the C language operate wint plain...
8
by: Alex | last post by:
Hi all, can someone please show me how to get the size of a file with ANSI C? both in text mode and binary mode. thanks in advance.
21
by: siroregano | last post by:
Hi Everyone- I'm new to this group, and almost-as-new to asking programming questions publicly, so please forgive me if I miss a convention or two! I have a text file, around 40,000 lines...
2
by: Youssef Mesri | last post by:
I have two files, the first one is an ascii file and the second is a binary one. I want to add the ascii file on the end of the binary file in order to obtain a one binary file: I have done...
9
by: jbrewer | last post by:
I'm currently implementing an XML-RPC service in Python where binary data is sent to the server via URLs. However, some clients that need to access the server may not have access to a web server,...
0
by: phoenix7 | last post by:
Dear all, I want to store some data in form of a zip file into an access database. I created a table with with a column of type OLE Object, then I designed a form to insert data to the table....
0
by: RN | last post by:
Hi everyone, First please let me explain. I am attempting to store pdf files in an MS Access DB (2000) and I have written a subroutine to do this. My code seems to work perfectly (see code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.