Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DeviceIOControl () fails with error 87

DeviceIOControl () fails with error 87

Scheduled Pinned Locked Moved C / C++ / MFC
helpsecurity
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vasu_sri
    wrote on last edited by
    #1

    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,
    		&amp;pdg,sizeof(pdg),&amp;dwBytesReturned,NULL);
    	dw= GetLastError();
    
    	CloseHandle(hDevice);
    	return pdg.Extents-&gt;DiskNumber;
    }
    return FALSE;
    

    }

    Regards, Srinivas

    D L V 3 Replies Last reply
    0
    • V vasu_sri

      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,
      		&amp;pdg,sizeof(pdg),&amp;dwBytesReturned,NULL);
      	dw= GetLastError();
      
      	CloseHandle(hDevice);
      	return pdg.Extents-&gt;DiskNumber;
      }
      return FALSE;
      

      }

      Regards, Srinivas

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Your code worked fine for me. How are you calling GetDriveNumber()? Are you calling GetLastError() regardless of what DeviceIoControl() 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

      1 Reply Last reply
      0
      • V vasu_sri

        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,
        		&amp;pdg,sizeof(pdg),&amp;dwBytesReturned,NULL);
        	dw= GetLastError();
        
        	CloseHandle(hDevice);
        	return pdg.Extents-&gt;DiskNumber;
        }
        return FALSE;
        

        }

        Regards, Srinivas

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • V vasu_sri

          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,
          		&amp;pdg,sizeof(pdg),&amp;dwBytesReturned,NULL);
          	dw= GetLastError();
          
          	CloseHandle(hDevice);
          	return pdg.Extents-&gt;DiskNumber;
          }
          return FALSE;
          

          }

          Regards, Srinivas

          V Offline
          V Offline
          vasu_sri
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • V vasu_sri

            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

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups