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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting ERROR_INSUFFICIENT_BUFFER error in DeviceIoControl Function

Getting ERROR_INSUFFICIENT_BUFFER error in DeviceIoControl Function

Scheduled Pinned Locked Moved C / C++ / MFC
helpsecurityquestion
2 Posts 2 Posters 1 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.
  • L Offline
    L Offline
    learningvisualc
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • L learningvisualc

      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

      A Offline
      A Offline
      Andrew Brock
      wrote on last edited by
      #2

      Not sure if it is just the way u copied it to code project, but you need to escape each of the back slashes in the drive name like "\\\\.\\PhysicalDrive0" also add a comma in after that string. Once I applied those changes your code worked for me.

      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