DeviceIOControl () fails with error 87
-
hi everybody, iam using <b>DeviceIoControl()</b> to get the physical drive number. but the problem is that the DeviceIoControl is giving error 87.means that parameter is incoorect. please help me anybody knows this solution.
int GetDriveNumber(CString strDrive)
{
TCHAR lpWindowsDir[_MAX_PATH+1];
VOLUME_DISK_EXTENTS pdg;
CString strDevice;
HANDLE hDevice =NULL;
DWORD dw;
DWORD dwBytesReturned;
GetWindowsDirectory(lpWindowsDir,_MAX_PATH+1);strDevice.Format(\_T("\\\\\\\\.\\\\%s:"),strDrive); hDevice = CreateFile(strDevice, // the device GENERIC\_READ, // open for reading FILE\_SHARE\_READ|FILE\_SHARE\_WRITE, // share mode NULL, // default security OPEN\_EXISTING, // open existing FILE\_ATTRIBUTE\_NORMAL, // normal file NULL); if(hDevice != INVALID\_HANDLE\_VALUE) { BOOL bIsSucces = DeviceIoControl(hDevice,IOCTL\_VOLUME\_GET\_VOLUME\_DISK\_EXTENTS,NULL,0, &pdg,sizeof(pdg),&dwBytesReturned,NULL); dw= GetLastError(); CloseHandle(hDevice); return pdg.Extents->DiskNumber; } return FALSE;
}
Regards, Srinivas
-
hi everybody, iam using <b>DeviceIoControl()</b> to get the physical drive number. but the problem is that the DeviceIoControl is giving error 87.means that parameter is incoorect. please help me anybody knows this solution.
int GetDriveNumber(CString strDrive)
{
TCHAR lpWindowsDir[_MAX_PATH+1];
VOLUME_DISK_EXTENTS pdg;
CString strDevice;
HANDLE hDevice =NULL;
DWORD dw;
DWORD dwBytesReturned;
GetWindowsDirectory(lpWindowsDir,_MAX_PATH+1);strDevice.Format(\_T("\\\\\\\\.\\\\%s:"),strDrive); hDevice = CreateFile(strDevice, // the device GENERIC\_READ, // open for reading FILE\_SHARE\_READ|FILE\_SHARE\_WRITE, // share mode NULL, // default security OPEN\_EXISTING, // open existing FILE\_ATTRIBUTE\_NORMAL, // normal file NULL); if(hDevice != INVALID\_HANDLE\_VALUE) { BOOL bIsSucces = DeviceIoControl(hDevice,IOCTL\_VOLUME\_GET\_VOLUME\_DISK\_EXTENTS,NULL,0, &pdg,sizeof(pdg),&dwBytesReturned,NULL); dw= GetLastError(); CloseHandle(hDevice); return pdg.Extents->DiskNumber; } return FALSE;
}
Regards, Srinivas
Your code worked fine for me. How are you calling
GetDriveNumber()
? Are you callingGetLastError()
regardless of whatDeviceIoControl()
returns."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
hi everybody, iam using <b>DeviceIoControl()</b> to get the physical drive number. but the problem is that the DeviceIoControl is giving error 87.means that parameter is incoorect. please help me anybody knows this solution.
int GetDriveNumber(CString strDrive)
{
TCHAR lpWindowsDir[_MAX_PATH+1];
VOLUME_DISK_EXTENTS pdg;
CString strDevice;
HANDLE hDevice =NULL;
DWORD dw;
DWORD dwBytesReturned;
GetWindowsDirectory(lpWindowsDir,_MAX_PATH+1);strDevice.Format(\_T("\\\\\\\\.\\\\%s:"),strDrive); hDevice = CreateFile(strDevice, // the device GENERIC\_READ, // open for reading FILE\_SHARE\_READ|FILE\_SHARE\_WRITE, // share mode NULL, // default security OPEN\_EXISTING, // open existing FILE\_ATTRIBUTE\_NORMAL, // normal file NULL); if(hDevice != INVALID\_HANDLE\_VALUE) { BOOL bIsSucces = DeviceIoControl(hDevice,IOCTL\_VOLUME\_GET\_VOLUME\_DISK\_EXTENTS,NULL,0, &pdg,sizeof(pdg),&dwBytesReturned,NULL); dw= GetLastError(); CloseHandle(hDevice); return pdg.Extents->DiskNumber; } return FALSE;
}
Regards, Srinivas
Hi Srinivas, What type of storage device are you using this control code on? You need to call GetLastError and check to see if the buffer you passed was too small. This control code can return an array greater than your buffer size. Best Wishes, -David Delaune
-
hi everybody, iam using <b>DeviceIoControl()</b> to get the physical drive number. but the problem is that the DeviceIoControl is giving error 87.means that parameter is incoorect. please help me anybody knows this solution.
int GetDriveNumber(CString strDrive)
{
TCHAR lpWindowsDir[_MAX_PATH+1];
VOLUME_DISK_EXTENTS pdg;
CString strDevice;
HANDLE hDevice =NULL;
DWORD dw;
DWORD dwBytesReturned;
GetWindowsDirectory(lpWindowsDir,_MAX_PATH+1);strDevice.Format(\_T("\\\\\\\\.\\\\%s:"),strDrive); hDevice = CreateFile(strDevice, // the device GENERIC\_READ, // open for reading FILE\_SHARE\_READ|FILE\_SHARE\_WRITE, // share mode NULL, // default security OPEN\_EXISTING, // open existing FILE\_ATTRIBUTE\_NORMAL, // normal file NULL); if(hDevice != INVALID\_HANDLE\_VALUE) { BOOL bIsSucces = DeviceIoControl(hDevice,IOCTL\_VOLUME\_GET\_VOLUME\_DISK\_EXTENTS,NULL,0, &pdg,sizeof(pdg),&dwBytesReturned,NULL); dw= GetLastError(); CloseHandle(hDevice); return pdg.Extents->DiskNumber; } return FALSE;
}
Regards, Srinivas
i got it, where is the problem. i declared as #pragma pack(push, 1) in stdafx.h file. it is working perfect,if i removed #pragma pack(push, 1) in a stdafx.h file. but i need #pragma pack(push, 1) some where in my code, how can i disable this pragma pack1 through code. tell me if anybody knows this soultion thanks
Regards, Srinivas
-
i got it, where is the problem. i declared as #pragma pack(push, 1) in stdafx.h file. it is working perfect,if i removed #pragma pack(push, 1) in a stdafx.h file. but i need #pragma pack(push, 1) some where in my code, how can i disable this pragma pack1 through code. tell me if anybody knows this soultion thanks
Regards, Srinivas
Hi Srinivas, You should only add this #pragma pack[^] around the structs,classes that require packing. After the struct/class declaration you add:
#pragma pack(pop)
This will allow the other data types to have previous alignment. Best Wishes, -David Delaune