Witam, mam problem z pobraniem z windows API czy dysk (partycja) jest w MBR czy GPT lub RAW. Funkcja zwraca mi : DeviceIoControl failed with error : 0.
Kod funkcji :
QString windows_drive_identifiaction::device_partition_style(char partitions)
{
HANDLE hDevice;
QString partition_style;
std::wstring logicalDrive = L"\\\\.\\";
wchar_t drive[3];
drive[0] = partitions;
drive[1] = L':';
drive[2] = L'\0';
logicalDrive.append(drive);
hDevice = CreateFile(
logicalDrive.c_str(),
0,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
DWORD bytesRet;
DRIVE_LAYOUT_INFORMATION_EX* dlix = (DRIVE_LAYOUT_INFORMATION_EX*)malloc(5120);
if(dlix == NULL)
{
qDebug() << "Memory Allocation failed";
CloseHandle(hDevice);
}
bool ioctlSucceed = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, (LPVOID)&dlix, 5120, (LPDWORD)&bytesRet, NULL);
if(ioctlSucceed)
{
qDebug() << "Success";
qDebug() << "Number of partitions : " << dlix->PartitionCount;
switch(dlix->PartitionStyle){
case PARTITION_STYLE_MBR:
qDebug() << "Partition style is MBR";
partition_style = "MBR";
break;
case PARTITION_STYLE_GPT:
qDebug() << "Partition style is GPT";
partition_style = "GPT";
break;
case PARTITION_STYLE_RAW:
qDebug() << "Partition style is RAW";
partition_style = "RAW";
break;
}
}else{
qDebug() << "DeviceIoControl failed with error : " << GetLastError();
}
free((void*) dlix);
CloseHandle(hDevice);
return partition_style;
}