현재 샘플 하드 드라이브 이미지의 파티션에 대한 정보 검색을 자동화하는 C++ 프로그램을 작성하려고합니다.이 정보는 디스크의 파티션 수와 각 파티션의 정보입니다. 섹터, 크기 및 파일 시스템 유형을 시작합니다.잘못된 함수 호출 "IOCTL_DISK_GET_DRIVE_LAYOUT_EX"
저는이 시점에서 MSDN 기능, microsofts inbuilt 명령을 사용하는 것이 가장 좋은 방법이라고 확신합니다. "IOCTL_DISK_GET_DRIVE_LAYOUT_EX"함수를 사용하려고하는데 내 오류 호출에 따라 함수가 올바르지 않습니다. 내가 프로그램을 디버깅 할 때 bool 값이 "IOCTL_DISK_GET_DRIVE_LAYOUT_EX"호출 후에 변경되지 않은 것으로 나타나면 bResult 값을 반환하지 않는다는 의미입니다.
Microsoft Visual C++ Express Edition을 사용하고 있습니다. 사람들이 내 코드를보고 내가 뭘 잘못했다고 생각하는지 말해 주면 많은 도움이 될 것입니다.
#define UNICODE 1
#define _UNICODE 1
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
#define wszDrive L"\\\\.\\PhysicalDrive6"
BOOL GetDriveParition(LPWSTR wszPath, DRIVE_LAYOUT_INFORMATION_EX *pdg)
{
HANDLE hDevice = INVALID_HANDLE_VALUE; // handle to the drive to be examined
BOOL bResult = FALSE; // results flag
DWORD junk = 0; // discard results
hDevice = CreateFileW(wszPath, // drive to open
0, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
return (FALSE);
}
bResult = DeviceIoControl(
hDevice, // handle to device
IOCTL_DISK_GET_DRIVE_LAYOUT_EX, // dwIoControlCode
NULL, // lpInBuffer
0, // nInBufferSize
pdg, // lpOutBuffer
sizeof(*pdg), // nOutBufferSize
&junk, // lpBytesReturned
NULL); // lpOverlapped
CloseHandle(hDevice);
return (bResult);
}
int wmain(int argc, wchar_t *argv[])
{
DRIVE_LAYOUT_INFORMATION_EX pdg; // disk drive partition structure
BOOL bResult = FALSE; // generic results flag
bResult = GetDriveParition (wszDrive, &pdg);
if (bResult)
{
wprintf(L"Drive path = %ws\n", wszDrive);
wprintf(L"Partition Style = %I64d\n", pdg.PartitionStyle);
wprintf(L"Partition Count = %ld\n", pdg.PartitionCount);
system("Pause");
}
else
{
wprintf (L"GetDrivePartition failed. Error %ld.\n", GetLastError());
system("Pause");
}
return ((int)bResult);
}
이 함수 후'GetLastError'를 호출하고 문제가 무엇인지를 참조하십시오? –
오류 122는 "시스템 호출로 전달 된 데이터 오류가 너무 작음"을 의미합니다 ... 구조체를 먼저 초기화해야합니까? –
의견을 주셔서 감사합니다. 가능한 한 빨리 시도해 보겠습니다. 결과가보고됩니다. –