473,326 Members | 2,813 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,326 software developers and data experts.

Writing binary file

Hi Sharpies,

I have a C program I am converting it into C#. Everything is fine
except this process creates a 6K byte binary file. This file initially
filled with 6K null and then start populating only the fields with
value in specified locations(3 seperate structures). The way the C does
is by creating a structures, which will be filled with null initially.
Then selectivly populating only the fields with values and only up to
the length of the string. The biggest structure is 2K in size.

What is the best approach to do this in c#?

Nov 16 '05 #1
2 1728
DBC User,

I assume this also means that you are writing the structures through a
call to WriteFile, writing the structure directly to the file.

You could do this in .NET, I believe, if your structure is simple. By
simple, I mean that the structure has primitive types, embedded arrays in
it, no references to something outside the structure (basically, all the
information is contained in the memory of the structure). If this is the
case, then you can get a pointer to the structure in unsafe code, and then
pass that through interop to the WriteFile function through the P/Invoke
layer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DBC User" <ks*****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi Sharpies,

I have a C program I am converting it into C#. Everything is fine
except this process creates a 6K byte binary file. This file initially
filled with 6K null and then start populating only the fields with
value in specified locations(3 seperate structures). The way the C does
is by creating a structures, which will be filled with null initially.
Then selectivly populating only the fields with values and only up to
the length of the string. The biggest structure is 2K in size.

What is the best approach to do this in c#?

Nov 16 '05 #2
Is there a link somewhere I can lookup or read more on using Interop
Thanks.

Nov 16 '05 #3

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

Similar topics

4
by: john smith | last post by:
Hi, I have a file format that is going to contain some parts in ascii, and some parts with raw binary data. Should I open this file with ios::bin or no? For example: filename: a.bin number of...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
4
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have...
5
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just...
3
by: Romain | last post by:
Hello, I am writing out a binary file. I figured that the number "10" is automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are line feed and carriage return. I know it does...
6
by: DanielEKFA | last post by:
Hey there :) I was once told that the STL classes had member functions to write their data to disk and to restore that data. Searching google (and why are there no "stl" or "map" manpages?), it...
2
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is written to work on data from a file (not from an...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
5
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.