This code should read in some data from sector zero off of a USB flash drive, then print out some of the data. However when I run it there is nothing that was put in the buffer.
int _tmain(int argc, _TCHAR* argv[])
{
int ReadSect = 0;
char diskname[60];
sprintf_s(diskname, "\\\\.\\K:", 'K');
HANDLE DiskHandle = CreateFile((LPCTSTR) diskname , GENERIC_READ,FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
// set up the offsets for the addresses passed to setFilePointer, and ReadFile
long lo_offset, hi_offset;
LPDWORD temp = 0;
lo_offset = ReadSect << 9;
hi_offset = ReadSect >> 23;
(void) SetFilePointer( DiskHandle, 0, &hi_offset, FILE_BEGIN);
char buf[1024];
for(int i = 0; i<512;i++) {
buf[i]='X';
}
if (! ReadFile(DiskHandle, buf, 512, (LPDWORD)&lo_offset, NULL) ) {
printf("error reading sector %ld\n", ReadSect);
CloseHandle(DiskHandle);
}
for(int i = 0; i<512;i++) {
cout<<(char)buf[i];
}
cout<<endl<<endl<<endl;
getchar();
}