I need to read binary data file written by C++ program, using my C#
application.
How do i marshal the bytes i read with my C# code to .NET types.
The data is numbers (integers float doubles etc..) and strings.
I looked at the Marshal class but did not know how to use it with file.
Please add few code lines.
Thanks alot
Jan 19 '06
14 4154
Willy,
I don't know if you notice but the binary data file was written by C++.
I am not sure that type bits written into the binary file, using C++,
is the same as type bits writen using .NET.
Vertilka
"Vertilka" <ve******@gmail .com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
| Willy,
|
| I don't know if you notice but the binary data file was written by C++.
| I am not sure that type bits written into the binary file, using C++,
| is the same as type bits writen using .NET.
|
| Vertilka
|
This is the first thing you should try to find out, right? You can't read a
file if you don't know the data types used in the file.
You said it's a binary data file, where is the data file written? On what
system (Windows, Unix, mainframe). Things to look for are endianess, char
encoding and eventual padding. If the file is written on Windows system,
then you are almost certain that the binary and floating point types are
exactly the same, more problematic are the char arrays and strings (which
are basically the same as arrays of chars once serialized), here you have to
know the encoding used so that you know how to read and to decode them.
Willy.
Vertilka <ve******@gmail .com> wrote: Jon, Nicholas, Thanks for your answers.
Can you both post code snippets. Lets say that i have 8 bytes that i want to get a bouble from them.
double d = BitConverter.In t64BitsToDouble (Marshall.ReadI nt64(...));
Of course, that assumes it's in the right format. Worth trying to see.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
again, friends...
i have a byte array with data.
i know for example that the first 8 bytes are double.
now.
with this line:
double d = BitConverter.In t64BitsToDouble (Marshall.ReadI nt64(...));
i need to give intptr to ReadInt64.
how to convert byte array to intptr
thanks.
Vertilka <ve******@gmail .com> wrote: again, friends...
i have a byte array with data. i know for example that the first 8 bytes are double.
In that case I'm not sure where the Marshal class comes in at all.
That's what's been confusing us, I suspect.
now. with this line: double d = BitConverter.In t64BitsToDouble (Marshall.ReadI nt64(...)); i need to give intptr to ReadInt64. how to convert byte array to intptr
Use BitConverter.To Double then.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: wwj |
last post by:
void main()
{
char* p="Hello";
printf("%s",p);
*p='w';
printf("%s",p);
}
|
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....
|
by: twawsico |
last post by:
I have a piece of code that needs to read the contents of a binary file
(that I've created with another app) into an array of structures. The
binary data in the file represents just a series of singles that
correspond to those in my structure detailed below. So when I load the
file, all that I know for certain is that there will be some multiple
of these eight singles represented in the binary data.
My code below will read the data...
|
by: Michael McGarry |
last post by:
Hi,
I am using the marshal module in python to save a data structure to a
file. It does not appear to be portable. The data is saved on a Linux
machine. Loading that same data on a Mac gives me the bad marshal data
message.
Is this data really not portable or I am doing something wrong here. I
thought the whole point of using Python and similar cross platform
scripting languages to write once run everywhere, does that not hold
|
by: Mike |
last post by:
Hi,
The example below shows that result of a marshaled data structure is
nothing but a string
>>> data = {2:'two', 3:'three'}
>>> import marshal
>>> bytes = marshal.dumps(data)
>>> type(bytes)
<type 'str'>
| |
by: Edvin |
last post by:
Why is binary array written to a file different
than when converting the binary array to string
and then writing it to file! For example:
// --- Allocate byte array
byte arrByte = new byte;
for( int i=1; i< arrByte.Length; i++ )
arrByte = (byte)i;
|
by: masood.iqbal |
last post by:
Hi,
Kindly excuse my novice question. In all the literature on ifstream
that I have seen, nowhere have I read what happens if you try to read
a binary file using the ">>" operator. I ran into the two problems
while trying to read a binary file.
1). All whitespace characters were skipped
2). Certain binary files gave a core dump
|
by: swetha |
last post by:
HI Every1,
I have a problem in reading a binary file.
Actually i want a C program which reads in the data from a file which
is in binary format and i want to update values in it.
The file consists of structures of type----
struct record {
int acountnum;
char name;
float value;
|
by: rory |
last post by:
I can't seem to append a string to the end of a binary file. I'm using
the following code:
fstream outFile("test.exe", ios::in | ios::out | ios::binary |
ios::ate | ios::app)
outFile.write("teststring", 10);
outFile.close();
If I leave out the ios::ate and ios::app modes my string is written to
the start of the file as I'd expect but I want to write the data to
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| | |