Click here to Skip to main content
15,887,256 members
Home / Discussions / C#
   

C#

 
AnswerRe: Returning Object From HashTable Pin
Member 94836444-Oct-12 1:59
Member 94836444-Oct-12 1:59 
AnswerRe: Returning Object From HashTable Pin
Manfred Rudolf Bihy4-Oct-12 2:22
professionalManfred Rudolf Bihy4-Oct-12 2:22 
AnswerRe: Returning Object From HashTable Pin
Bernhard Hiller4-Oct-12 21:05
Bernhard Hiller4-Oct-12 21:05 
Questionbusiness process management Pin
Sagar Pulidindi4-Oct-12 1:04
Sagar Pulidindi4-Oct-12 1:04 
AnswerRe: BUSINESS PROCESS MANAGEMENT Pin
OriginalGriff4-Oct-12 9:34
mveOriginalGriff4-Oct-12 9:34 
QuestionC# Pin
S Akshay4-Oct-12 0:19
S Akshay4-Oct-12 0:19 
AnswerRe: C# Pin
Eddy Vluggen4-Oct-12 0:42
professionalEddy Vluggen4-Oct-12 0:42 
QuestionJQUERY in C# Pin
JabbarJahambana3-Oct-12 22:00
JabbarJahambana3-Oct-12 22:00 
AnswerRe: JQUERY in C# Pin
Pete O'Hanlon3-Oct-12 22:30
mvePete O'Hanlon3-Oct-12 22:30 
AnswerRe: JQUERY in C# Pin
palakshamb4-Oct-12 23:42
palakshamb4-Oct-12 23:42 
QuestionTagLibSharp help needed Pin
joost.versteegen3-Oct-12 20:42
joost.versteegen3-Oct-12 20:42 
AnswerRe: TagLibSharp help needed Pin
Smart Arab3-Oct-12 21:18
Smart Arab3-Oct-12 21:18 
AnswerRe: TagLibSharp help needed Pin
joost.versteegen3-Oct-12 21:41
joost.versteegen3-Oct-12 21:41 
QuestionEquation on c# Pin
sabuhi_asad3-Oct-12 20:41
sabuhi_asad3-Oct-12 20:41 
AnswerRe: Equation on c# Pin
Richard MacCutchan3-Oct-12 21:41
mveRichard MacCutchan3-Oct-12 21:41 
QuestionImplementing Private Inheritence Pin
AmbiguousName3-Oct-12 19:07
AmbiguousName3-Oct-12 19:07 
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
mvePete 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 

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.