15
Jan
Posted by support as Win32/MFC 1,021 views
How to read the sectors of physical drive under win32?
The API ReadFile is most useful function, and with it, you can read the physical sectors directly.
Here is a sample function, BOOL ReadSectors(…)
BOOL ReadSectors(
BYTE bDrive, //drive index
DWORD dwStartSector, //start sector
WORD wSectors, //sectors number
LPBYTE lpSectBuff)
{
 if (bDrive == 0) return 0;
 char devName[] = “\\\\.\\A:”;
 devName[4] =’A’ + bDrive – 1;
 HANDLE hDev = CreateFile(devName, GENERIC_READ,
FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
 if (hDev == INVALID_HANDLE_VALUE) return 0;
 SetFilePointer(hDev, 512 * dwStartSector,
0, FILE_BEGIN);
 DWORD dwCB;
 BOOL bRet = ReadFile(hDev, lpSectBuff,
512 * wSectors, &dwCB, NULL);
 CloseHandle(hDev);
 return bRet;
}
Tags:
API, How-to, sdk, win32
RSS feed for comments on this post · TrackBack URI
Leave a reply