473,387 Members | 1,485 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,387 software developers and data experts.

Reading a binary file

RML
Hi,

My VS 2005 VB app reads a binary file that was created by a VS 2005 VC++
WinCE app. The VC++ app writes the following structure to the file.

typedef struct {
short ID;
TCHAR Num[10];
} PARTS_STRUCT;

In my VB code I read the file with this code...

<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Public Structure Parts_Struct
Public ID As Short
<MarshalAs(UnmanagedType.TBStr, SizeConst:=10)> _
Public Num As String
End Structure

Dim Parts As New Parts_Struct
Dim fs As New FileStream(FName, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fs)
Parts.ID = br.ReadInt16()
Parts.Num = br.ReadChars(20)

When I run the code, the ID field is Ok, but I only get the 1st letter that
was saved in the "Num" field.

RML
May 8 '06 #1
2 1412
"RML" <RM*@discussions.microsoft.com> schrieb:
My VS 2005 VB app reads a binary file that was created by a VS 2005 VC++
WinCE app. The VC++ app writes the following structure to the file.

typedef struct {
short ID;
TCHAR Num[10];
} PARTS_STRUCT;

In my VB code I read the file with this code...

<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Public Structure Parts_Struct
Public ID As Short
<MarshalAs(UnmanagedType.TBStr, SizeConst:=10)> _
Public Num As String


Try changing 'TBStr' to 'UnmanagedType.ByValTStr'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
May 8 '06 #2
RML
Thanks. I did try that and still get the same results.
"Herfried K. Wagner [MVP]" wrote:
"RML" <RM*@discussions.microsoft.com> schrieb:
My VS 2005 VB app reads a binary file that was created by a VS 2005 VC++
WinCE app. The VC++ app writes the following structure to the file.

typedef struct {
short ID;
TCHAR Num[10];
} PARTS_STRUCT;

In my VB code I read the file with this code...

<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Public Structure Parts_Struct
Public ID As Short
<MarshalAs(UnmanagedType.TBStr, SizeConst:=10)> _
Public Num As String


Try changing 'TBStr' to 'UnmanagedType.ByValTStr'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 8 '06 #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...
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
30
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
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;
9
by: Use*n*x | last post by:
Hello, I have a binary file (image file) and am reading 4-bytes at a time. The File size is 63,480,320 bytes. My assumption is that if I loop through this file reading 4 bytes at a time, I...
3
by: The Cool Giraffe | last post by:
Regarding the following code i have a problem. void read () { fstream file; ios::open_mode opMode = ios::in; file.open ("some.txt", opMode); char *ch = new char; vector <charv; while...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...

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.