IOCTL_DISK_GET_DRIVE_LAYOUT_EX工作不正常
IOCTL_DISK_GET_DRIVE_LAYOUT_EX Not working correctly
我有一个硬盘,上面有3个分区。当我使用IOCTL_disk_GET_DRIVE_LAYOUT_EX时,对象(在我的代码中是"pdg"对象)只返回数组1的分区信息,即使它说找到了4个分区。我缺少什么,使得partitionEntry(必须使用对象pdg的调试器进行partitionEntry)显示所有3个分区。我到处找了一些信息,但都找不到。不同的论坛,msdn。。。
下面是我的代码
#define UNICODE 1
#define _UNICODE 1
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
#define wszDrive L"\\.\PhysicalDrive3"
BOOL GetDrive(LPWSTR wszPath)
{
HANDLE hDevice = INVALID_HANDLE_VALUE; // handle to the drive to be examined
BOOL bResult = FALSE; // results flag
DWORD junk = 0; // discard results
DWORD hr;
DWORD szNewLayout = sizeof(DRIVE_LAYOUT_INFORMATION_EX) + sizeof(PARTITION_INFORMATION_EX) * 4 * 25 ;
DRIVE_LAYOUT_INFORMATION_EX *pdg = (DRIVE_LAYOUT_INFORMATION_EX*) new BYTE[szNewLayout];
hDevice = CreateFileW(wszPath, // drive to open
GENERIC_READ|GENERIC_WRITE, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
0); // do not copy file attributes
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
hr = GetLastError();
return (FALSE);
}
bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_DISK_GET_DRIVE_LAYOUT_EX, // operation to perform
NULL, 0, // no input buffer
pdg, szNewLayout,// sizeof(*pdg)*2, // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O
if(!bResult)
{
hr = GetLastError();
LPTSTR errorText = NULL;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, 0, NULL);
wprintf(L"Error", errorText);
}
CloseHandle(hDevice);
return (bResult);
}
int wmain(int argc, wchar_t *argv[])
{
BOOL bResult = FALSE; // generic results flag
bResult = GetDrive(wszDrive);
system ("pause");
return ((int)bResult);
}
感谢
其他分区数据在那里,但调试器没有显示。
DRIVE_LAYOUT_INFORMATION_EX.PartitionEntry被声明为长度为1的数组,但实际上是动态分配的,以匹配PartitionCount。
在DeviceIoControl
后设置断点,右键单击pdg
,选择QuickWatch。。。,然后将表达式更新为pdg->PartitionEntry[1]
,然后更新[2]等,以检查其他分区。
或者,添加一个循环来遍历PartitionEntry
数组并打印出结果:
for( int i = 0; i < pdg->PartitionCount; i++ ) {
printf( "partition %d: %dn", i, pdg->PartitionEntry[i].PartitionStyle);
}
相关文章:
- QSqlquery prepare()和bindvalue()不工作
- 导入库可以跨dll版本工作吗
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- C++为线程工作动态地分割例程
- 为什么我的 std::ref 无法按预期工作?
- 布尔比较运算符是如何在C++中工作的
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- <<操作员在下面的行中工作
- 有人能解释一下为什么下界是这样工作的吗C++的
- ExtractIconEx:可以工作,但偶尔会崩溃
- C++中的memset函数工作不正常
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- 链表c++插入,所有情况都已检查,但没有任何工作
- 为什么stream::忽略未按预期工作