|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading Binary file created by VC++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.ByValTStr, 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(10) In the binary file, the Num fiedl contains the text "123". When I run the code, the ID field is Ok, but I only get the 1st letter if the "Num" field ("0").. If I change the Num field type to Char(), it gets filled with this... Num[0] = "1" Num[1] = Nothing Num[2] = "2" Num[3] = Nothing Num[4] = "3" Num[5] = Nothing I also tried changing the "CharSet" parameter in the Structlayout() to Ansi and Unicode, bit still get the same results. Looks like I am close, but still missing something. Can anyone point me in the right direction? RML RML wrote:
Show quoteHide quote >Hi, The file is binary - you can't read characters, you have to read bytes > >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.ByValTStr, 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(10) > > and then convert them into a string. T
Rewrite ...
DataTable.Select() is bugged? Getting a file's ContentType OpenGL Control Flickering Problem RegEx for splitting comma delimited text, HOW Control for Sql Connection? running app on network drive Attaching a thread windows forms finder (help me) Operation must use an updateable query EXCEPTION when trying to update excel |
|||||||||||||||||||||||