我正在尝试使硬盘上的分区偏移。我这样做:
PDRIVE_LAYOUT_INFORMATION_EX partitions;
DWORD partitionsSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX)
+ 127 * sizeof(PARTITION_INFORMATION_EX);
partitions = (PDRIVE_LAYOUT_INFORMATION_EX)malloc(partitionsSize);
HANDLE h = CreateFile(L"\\\\.\\PhysicalDrive0", FILE_ANY_ACCESS ,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, 0);
if (h == INVALID_HANDLE_VALUE)
{
// handle error and exit
}
if (DeviceIoControl(h, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, partitions,
partitionsSize, 0, NULL) != 0)
{
// do stuff with partitions here
}
它在Windows 10上运行良好,但在Windows 7上(通过DeviceIoControl调用)失败。调试器输出为:
Exception at 0x7fefcc3b2b2, code: 0xc0000005: write access violation at: 0x1, flags=0x0
我试过:以管理员身份运行,在CreateFile,Google上更改文件访问参数(可能不够好)
我使用:Microsoft Visual Studio 14.0
最佳答案
我不专心地阅读文档。答案在注释中(由@RbMm回答)
关于c++ - DeviceIoControl调用崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50961969/