binary file/o in managed c++

  • Thread starter The unProfessional
  • Start date
T

The unProfessional

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 BinaryFormatters, 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?
 
R

Ronald Laeremans [MSFT]

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
 
T

The unProfessional

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 said:
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 said:
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 BinaryFormatters, 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?
 
R

Ronald Laeremans [MSFT]

Yes, you can mail me. The obvious transformation of my posting alias is my
real MS email address.

Ronald

The unProfessional said:
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 said:
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 said:
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 BinaryFormatters, 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?
 

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