If
hDevice is valid, the static sector size might be your problem. You should call RaiseLastOSError() after a failed
API call to display a specific error message.
Zitat von
MSDN:
You can open a physical or logical drive using the CreateFile() application programming interface (
API) with these device names provided that you have the appropriate
access rights to the drive (that is, you must be an administrator). You must use both the CreateFile() FILE_SHARE_READ and FILE_SHARE_WRITE flags to gain
access to the drive.
Once the logical or physical drive has been opened, you can then perform direct I/O to the data on the entire drive. When performing direct disk I/O, you must seek, read, and write in multiples of sector sizes of the device and on sector boundaries. Call DeviceIoControl() using IOCTL_DISK_GET_DRIVE_GEOMETRY to get the bytes per sector, number of sectors, sectors per track, and so forth, so that you can compute the size of the buffer that you will need.