المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Getting ERROR_INSUFFICIENT_BUFFER error in DeviceIoControl Function



C++ Programming
01-11-2011, 06:09 PM
Hi all,

I am trying to get Logical drives of a hard disk(\\.\PhysicalDrive0).

I have tried using DeviceIoControl function for it but i am getting GetLastError() = 122 i.e. ERROR_INSUFFICIENT_BUFFER error.
My code is as follows:-

HANDLE hDevice;

hDevice = CreateFile("\\.\PhysicalDrive0" // drive
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


PARTITION_INFORMATION_EX obj;
DWORD cb;


BOOL iu = DeviceIoControl(hDevice, // handle to a partition
IOCTL_DISK_GET_PARTITION_INFO_EX, // dwIoControlCode
NULL, // lpInBuffer
0, // nInBufferSize
&obj, // output buffer
sizeof(obj), // size of output buffer
&cb, // number of bytes returned
NULL // OVERLAPPED structure
);
if(iu == 0)
{
DWORD err = GetLastError();
CString str;
str.Format("%d",err);
AfxMessageBox(str);
}
CloseHandle(hDevice);
I am not getting where exactly is the problem...
How can i do this..
Thanks in advance