473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

binary file/o in managed c++

I'm having difficulty figuring out a simple way to dump unmanaged structure
and/or class data to binary files.

In standard C++:
--------------------------
typedef struct tagS1
{
DWORD dwBlah;
CHAR szBlah[64];
} S1;

....

S1 s1;

FILE *fd = fopen ("c:\....", "wb");

fwrite (&s1, sizeof(s1), 1, fd);

fclose (fd);
--------------------------

I really don't want to have to move a ton of pre-defined structures to
managed code and use BinaryFormatter s, pad my strings, etc.

I attempted to use fwrite in managed c++, but it appears to cause an error
in the internal file-locking mechanism.

Ultimately, I'm hoping to take advantage of some of the managed set,
especially easy GUI creation, but I need some pure-C++ functionality (such
as what's described above). Doesn't managed C++ support the standard C++
libraries? If not, isn't that contrary to it's purpose?

Any info or advice would be GREATLY appreciated :)

I'd like to harness some of the ease of the .net framework (better than
MFC), but without losing the ability to write regular old C++. Is it even
possible?

--
Bill Merrill
Lead Developer
Merchant Companion
Nov 17 '05 #1
3 1522
There is no reason that I know off that fwrite should not work identically.
Do you have a small repro case you could share?

Ronald Laeremans
Visual C++ team

"The unProfessional" <sp**@shitbits. com> wrote in message
news:Eu******** ************@mp owercom.net...
I'm having difficulty figuring out a simple way to dump unmanaged
structure
and/or class data to binary files.

In standard C++:
--------------------------
typedef struct tagS1
{
DWORD dwBlah;
CHAR szBlah[64];
} S1;

...

S1 s1;

FILE *fd = fopen ("c:\....", "wb");

fwrite (&s1, sizeof(s1), 1, fd);

fclose (fd);
--------------------------

I really don't want to have to move a ton of pre-defined structures to
managed code and use BinaryFormatter s, pad my strings, etc.

I attempted to use fwrite in managed c++, but it appears to cause an error
in the internal file-locking mechanism.

Ultimately, I'm hoping to take advantage of some of the managed set,
especially easy GUI creation, but I need some pure-C++ functionality (such
as what's described above). Doesn't managed C++ support the standard C++
libraries? If not, isn't that contrary to it's purpose?

Any info or advice would be GREATLY appreciated :)

I'd like to harness some of the ease of the .net framework (better than
MFC), but without losing the ability to write regular old C++. Is it even
possible?

--
Bill Merrill
Lead Developer
Merchant Companion

Nov 17 '05 #2
Hi Ronald,

Thanks alot for your time.

I'll put together a quick example and send it on over... Should I email you
directly?

Sincerely,
Bill

"Ronald Laeremans [MSFT]" <ro*****@online .microsoft.com> wrote in message
news:O8******** ******@TK2MSFTN GP15.phx.gbl...
There is no reason that I know off that fwrite should not work identically. Do you have a small repro case you could share?

Ronald Laeremans
Visual C++ team

"The unProfessional" <sp**@shitbits. com> wrote in message
news:Eu******** ************@mp owercom.net...
I'm having difficulty figuring out a simple way to dump unmanaged
structure
and/or class data to binary files.

In standard C++:
--------------------------
typedef struct tagS1
{
DWORD dwBlah;
CHAR szBlah[64];
} S1;

...

S1 s1;

FILE *fd = fopen ("c:\....", "wb");

fwrite (&s1, sizeof(s1), 1, fd);

fclose (fd);
--------------------------

I really don't want to have to move a ton of pre-defined structures to
managed code and use BinaryFormatter s, pad my strings, etc.

I attempted to use fwrite in managed c++, but it appears to cause an error in the internal file-locking mechanism.

Ultimately, I'm hoping to take advantage of some of the managed set,
especially easy GUI creation, but I need some pure-C++ functionality (such as what's described above). Doesn't managed C++ support the standard C++ libraries? If not, isn't that contrary to it's purpose?

Any info or advice would be GREATLY appreciated :)

I'd like to harness some of the ease of the .net framework (better than
MFC), but without losing the ability to write regular old C++. Is it even possible?

--
Bill Merrill
Lead Developer
Merchant Companion


Nov 17 '05 #3
Yes, you can mail me. The obvious transformation of my posting alias is my
real MS email address.

Ronald

"The unProfessional" <sp**@shitbits. com> wrote in message
news:3q******** ************@mp owercom.net...
Hi Ronald,

Thanks alot for your time.

I'll put together a quick example and send it on over... Should I email
you
directly?

Sincerely,
Bill

"Ronald Laeremans [MSFT]" <ro*****@online .microsoft.com> wrote in message
news:O8******** ******@TK2MSFTN GP15.phx.gbl...
There is no reason that I know off that fwrite should not work

identically.
Do you have a small repro case you could share?

Ronald Laeremans
Visual C++ team

"The unProfessional" <sp**@shitbits. com> wrote in message
news:Eu******** ************@mp owercom.net...
> I'm having difficulty figuring out a simple way to dump unmanaged
> structure
> and/or class data to binary files.
>
> In standard C++:
> --------------------------
> typedef struct tagS1
> {
> DWORD dwBlah;
> CHAR szBlah[64];
> } S1;
>
> ...
>
> S1 s1;
>
> FILE *fd = fopen ("c:\....", "wb");
>
> fwrite (&s1, sizeof(s1), 1, fd);
>
> fclose (fd);
> --------------------------
>
> I really don't want to have to move a ton of pre-defined structures to
> managed code and use BinaryFormatter s, pad my strings, etc.
>
> I attempted to use fwrite in managed c++, but it appears to cause an error > in the internal file-locking mechanism.
>
> Ultimately, I'm hoping to take advantage of some of the managed set,
> especially easy GUI creation, but I need some pure-C++ functionality (such > as what's described above). Doesn't managed C++ support the standard C++ > libraries? If not, isn't that contrary to it's purpose?
>
> Any info or advice would be GREATLY appreciated :)
>
> I'd like to harness some of the ease of the .net framework (better than
> MFC), but without losing the ability to write regular old C++. Is it even > possible?
>
> --
> Bill Merrill
> Lead Developer
> Merchant Companion
>
>



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9802
by: armin walland | last post by:
hi group! i am writing a small tool to dump data from oracle databases and i want to implement the possibility to execute sql statements read from stdin or from a file. i have so far managed to do so, but every sql statement must be on a single line with no ";" at the end of each line. i would like to use an input file like this:
4
2414
by: projecktzero | last post by:
Well, I've managed to get an image into a postgre database, but now I'm having trouble getting it out. #! /usr/bin/env python from pyPgSQL import PgSQL def main(): connectdb = PgSQL.connect('server:port:database:username:password') cur = connectdb.cursor()
3
2463
by: Usenet User | last post by:
I am trying to read (and then save) a binary file which has certain data structures in it. (The file is in propritetary format produced by a 3rd party MFC application.) I know that those data structures would correspond to the structures similar to the one below: private struct MyStruct {
4
3695
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the following code that compiles OK. It runs and shows the requested output. However, after execution, it pops one of those windows to send error reports online to the porgram creator. I have managed to find where the error is but can't see what's wrong....
6
2732
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios, every now and then the client would timeout and have to re-initiate the request... TIA!
2
1770
by: Michael Kolias | last post by:
Hello everyone and happy holidays! I have a situation where I want to parse on the fly a stream of binary data. I am developing an httpmodule for asp.net for file uploading. I do not whant to use the built-in control because it's inadequate. In theory I would use a que and feed data as it comes in and then have a parser that extracts the data from the que, parse them and do whatever.
15
2412
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with two int32's as its data members, the binary file of that class must have a size of 8 bytes (i.e. only contains class data members, not methods etc.). Is serialization the answer to the above problem? If I understand correctly, the reason that...
2
1679
by: mpreisdorf | last post by:
I want to save the raw data of a class (without the .NET object overhead) to a binary file. For example: ref class Test { public: String^ name; Int32 number; ..... }
3
4041
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years in IE, Firefox and Opera on windows, and it works on a Mac with Firefox and Opera. But this fails in Safari with the generic message "A network error occurred while accessing this document". Here is a link to try out ...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10104
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.