2.2.5.1.12 file::ReadIntReadInt
Description
It is used to support Little Endian and Big Endian read and write binary data .
Syntax
UINT ReadInt( void * pDestBuffer, int nDataTypeSize, UINT nItemCount, BOOL bIsLittleEndian = TRUE )
Parameters
- pDestBuffer
- [output] Destination's buffer of store the int value
- nDataTypeSize
- [input] Must be size of datatype, for integal, 1, 2 and 4, for float. 4 and 8.
- nItemCount
- [input] Number of data;
- bIsLittleEndian
- [input] TRUE, use Little Endian way, FALSE use Big Endian way, default value is TRUE.
Return
The number of items read from file.
Examples
EX1
#define INT32_ITEM_COUNT 2
#define INT16_ITEM_COUNT 4
// ASCII: A B C D 1 2 3 4
// HEX : 41 42 43 44 31 32 33 34
void file_ReadInt_ex1()
{
file fil;
short i16[INT16_ITEM_COUNT], i1[INT16_ITEM_COUNT], i3[INT16_ITEM_COUNT];
long i32[INT32_ITEM_COUNT], i2[INT32_ITEM_COUNT], i4[INT32_ITEM_COUNT];
i16[0] = 0x4241;
i16[1] = 0x4443;
i16[2] = 0x3231;
i16[3] = 0x3433;
i32[0] = 0x44434241;
i32[1] = 0x34333231;
string strFile = "C:\\end.bin";
if( fil.Open(strFile, file::modeCreate | file::modeWrite ) )
{
int i = fil.WriteInt(i16, sizeof(short), INT16_ITEM_COUNT);
i = fil.WriteInt(i32, sizeof(long), INT32_ITEM_COUNT);
i = fil.WriteInt(i16, sizeof(short), INT16_ITEM_COUNT, FALSE);
i = fil.WriteInt(i32, sizeof(long), INT32_ITEM_COUNT, FALSE);
fil.Close();
}
else
{
string strPromptExist = "Before testing, please delete file: " + strFile;
MessageBox( NULL, strPromptExist );
}
if( fil.Open(strFile, file::modeRead|file::shareDenyWrite) )
{
int i = fil.ReadInt(i1, sizeof(short), INT16_ITEM_COUNT);
i = fil.ReadInt(i2, sizeof(long), INT32_ITEM_COUNT);
i = fil.ReadInt(i3, sizeof(short), INT16_ITEM_COUNT, FALSE);
i = fil.ReadInt(i4, sizeof(long), INT32_ITEM_COUNT, FALSE);
fil.Close();
}
}
Remark
See Also
file::WriteInt
Header to Include
origin.h
|