# Include <windows. h>
# Include <stdio. h>
Int main (INT argc, char ** argv)
{
Handle hfile;
Char * buffer;
DWORD bytesreaded = 0;
Uint datasize = 8;
// Open File
Hfile = createfile ("test. Data", generic_read, file_assist_read, null, open_existing,
File_attribute_readonly, null );
If (! Hfile)
{
Printf ("cann't open file \" test. Data \ "\ n ");
Return 1;
}
// Create buffer
Buffer = (char *) localalloc (lmem_moveable | lmem_zeroinit, 16 );
If (! Buffer)
{
Printf ("cann' t allocate memory! \ N ");
Return 2;
}
// Read File
If (! Readfile (hfile, buffer, datasize, & bytesreaded, null ))
{
Printf ("cann' t read file! \ N ");
Return 3;
}
// Close file
Closehandle (hfile );
// Print data
Printf ("Total % d bytes! \ N ", bytesreaded );
Char hi, low;
Char data;
Printf ("data: \ n ");
For (INT I = 0; I <bytesreaded; I ++)
{
Data = * (buffer + I );
Hi = (Data & 0xf0)> 4;
Low = Data & 0x0f;
Printf ("byte [% d]:", I );
If (Hi <10) printf ("% C", hi + '0 ');
Else printf ("% C", (hi-10) + 'A ');
If (low <10) printf ("% C", low + '0 ');
Else printf ("% C", (low-10) + 'A ');
Printf ("\ n ");
}
// Free buffer
Localfree (buffer );
Printf ("\ n ");
Return 0;
}