gpt4 book ai didi

c++ - DeviceIoControl 调用崩溃

转载 作者:行者123 更新时间:2023-11-30 05:00:02 29 4
gpt4 key购买 nike

我正在尝试在我的硬盘上进行分区偏移。我这样做:

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 上的文件访问参数,谷歌(可能不够好)

我使用:Microsoft Visual Studio 14.0

最佳答案

我不专心地阅读文档。答案在评论中(由@RbMm 回答)

one of the last 2 params (lpBytesReturned or lpOverlapped) must not be 0. and visual studio version, run as admin, change file access parameters on CreateFile - can not affect access violation on

关于c++ - DeviceIoControl 调用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961969/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com