Click here to Skip to main content
15,860,972 members
Home / Discussions / C#
   

C#

 
AnswerRe: Implementing Private Inheritence Pin
Peter_in_27803-Oct-12 19:21
professionalPeter_in_27803-Oct-12 19:21 
GeneralRe: Implementing Private Inheritence Pin
AmbiguousName3-Oct-12 19:33
AmbiguousName3-Oct-12 19:33 
GeneralRe: Implementing Private Inheritence Pin
Peter_in_27803-Oct-12 19:50
professionalPeter_in_27803-Oct-12 19:50 
AnswerRe: Implementing Private Inheritence Pin
Pete O'Hanlon3-Oct-12 22:19
subeditorPete O'Hanlon3-Oct-12 22:19 
AnswerRe: Implementing Private Inheritence Pin
jschell4-Oct-12 11:39
jschell4-Oct-12 11:39 
Questionprocess being called by C# app Pin
rachel_m3-Oct-12 18:28
rachel_m3-Oct-12 18:28 
AnswerRe: process being called by C# app Pin
Smart Arab3-Oct-12 20:54
Smart Arab3-Oct-12 20:54 
QuestionFail Read Int64 value from binary file created by C++ Pin
kisetsu3-Oct-12 14:49
kisetsu3-Oct-12 14:49 
I m developing a CE application to read data from binary files which created by C++ progam to do item validation.

Below is the docing of the C++ program..
// File Name: Ean2an.bin which is created by struct
struct EAN2AN_TYPE
{
__int64 ean:40; // 5 bytes, up to 12 digits
__int64 rec_no:24; // 3 bytes rec no in the c_ItemMaster File, up to 16 million records
};

// After bind data to struct, wil create the binary file
bool CreateBin_EAN2AN_TYPE()
{
if(mn_RecordCount_EAN2AN_TYPE == 0) return false;

FILE *binfile;

qsort(mc_EAN2AN_TYPE, mn_RecordCount_EAN2AN_TYPE, sizeof(struct EAN2AN_TYPE), qsort_EAN2AN_TYPE);
try
{
binfile = fopen(ms_Path_EAN2AN_TYPE, "wb");
fwrite(&mc_EAN2AN_TYPE, sizeof(struct EAN2AN_TYPE), mn_RecordCount_EAN2AN_TYPE, binfile);
}
catch(Exception ^ex)
{
TaskProgramLibrary::Message::ERR("Create EAN2AN_TYPE.bin fail!\r\n " + ex->Message);
}
finally
{
fclose(binfile);

mdw_FileSize_EAN2AN_TYPE = FileSize(ms_Path_EAN2AN_TYPE);
}

return true;
. }

I tried to read the data by using binary read(based on position) and use bitconverter to convert to int64 or using Marshal.PtrToStructure, but the value return is incorrect. Then i tried to read 5 bytes instead of 8 bytes from the file, but the value return stil incorrect.
Below is C# coding wrote
//Struct created in C#
[StructLayout(LayoutKind.Sequential)]
public struct EAN2AN_TYPE
{
[MarshalAs(UnmanagedType.I8)]
public Int64 ean;
[MarshalAs(UnmanagedType.I8)]
public Int64 rec_no;
}

//HOw i read in C#
//1.Read Int64 by Binary
private void ReadByBinary()
{
using (BinaryReader b = new BinaryReader(_fs))
{
while (b.PeekChar() != 0)
{
Int64 x = b.ReadInt64();
Console.WriteLine(x.ToString());

}
}

}

//2.Using Marshal to convert the Intptr to struct's field type
private object ReadByMarshal(Type iType)
{
_oType = iType;// typeof(System.Int64);
byte[] buffer = new byte[Marshal.SizeOf(_oType)];
//byte[] buffer = new byte[5];

object oReturn = null;

try
{
_fs.Read(buffer, 0, buffer.Length);

GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
oReturn = Marshal.PtrToStructure(handle.AddrOfPinnedObject(), _oType);
handle.Free();

return oReturn;
}
catch (Exception ex)
{
throw ex;
}
}


//3. Use Binary and use bit converter to convert to Int64
private void ReadByBinaryAndUseBitConverter()
{
using (BinaryReader b = new BinaryReader(_fs))
{
byte[] x = b.ReadBytes(8);
Int64 y = BitConverter.ToInt64(x, 0);
Console.WriteLine(y);

byte[] x2 = b.ReadBytes(8);
Int64 y2 = BitConverter.ToInt64(x2,0);
Console.WriteLine(y2);
}

}


//4. Use Marshal and convert to struct
public EAN2AN_TYPE GetStructValue()
{

byte[] buffer = new byte[Marshal.SizeOf(typeof(EAN2AN_TYPE)];

EAN2AN_TYPE oReturn = new EAN2AN_TYPE();

try
{
//if (EOF) return null;

_fs.Read(buffer, 0, buffer.Length);
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
IntPtr rawDataPtr = handle.AddrOfPinnedObject();

oReturn = (EAN2AN_TYPE)Marshal.PtrToStructure(rawDataPtr, typeof(EAN2AN_TYPE));

handle.Free();

if (_fs.Position >= _fs.Length)
Close();

return oReturn;
}
catch (Exception ex)
{
throw ex;
}
}

Anybody have any idea?

Thanks in advance
QuestionThere is an error in XML document calling a PHP Webservice Pin
RalphGielkens3-Oct-12 10:54
RalphGielkens3-Oct-12 10:54 
QuestionPassing object[] Elements as Parameters to Invoke() Pin
ezazazel3-Oct-12 7:04
ezazazel3-Oct-12 7:04 
AnswerRe: Passing object[] Elements as Parameters to Invoke() Pin
Matt T Heffron3-Oct-12 9:08
professionalMatt T Heffron3-Oct-12 9:08 
GeneralRe: Passing object[] Elements as Parameters to Invoke() Pin
ezazazel3-Oct-12 19:26
ezazazel3-Oct-12 19:26 
QuestionC# calling executable Pin
dcof3-Oct-12 3:57
dcof3-Oct-12 3:57 
AnswerRe: C# calling executable Pin
Pete O'Hanlon3-Oct-12 4:16
subeditorPete O'Hanlon3-Oct-12 4:16 
AnswerRe: C# calling executable Pin
Shameel3-Oct-12 4:51
professionalShameel3-Oct-12 4:51 
AnswerRe: C# calling executable Pin
Dave Kreskowiak3-Oct-12 5:35
mveDave Kreskowiak3-Oct-12 5:35 
GeneralRe: C# calling executable Pin
dcof3-Oct-12 8:07
dcof3-Oct-12 8:07 
GeneralRe: C# calling executable Pin
Pete O'Hanlon3-Oct-12 8:38
subeditorPete O'Hanlon3-Oct-12 8:38 
GeneralRe: C# calling executable Pin
Dave Kreskowiak3-Oct-12 13:45
mveDave Kreskowiak3-Oct-12 13:45 
QuestionC# Windows application not responding after 30 minutes Pin
sujithkumarsl2-Oct-12 10:13
sujithkumarsl2-Oct-12 10:13 
AnswerRe: C# Windows application not responding after 30 minutes Pin
Smart Arab2-Oct-12 10:58
Smart Arab2-Oct-12 10:58 
AnswerRe: C# Windows application not responding after 30 minutes Pin
Dave Kreskowiak2-Oct-12 12:35
mveDave Kreskowiak2-Oct-12 12:35 
GeneralOT Pin
Peter_in_27802-Oct-12 22:08
professionalPeter_in_27802-Oct-12 22:08 
GeneralRe: OT Pin
Dave Kreskowiak3-Oct-12 2:22
mveDave Kreskowiak3-Oct-12 2:22 
GeneralRe: OT Pin
Peter_in_27803-Oct-12 2:29
professionalPeter_in_27803-Oct-12 2:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.