How to use IOCTL_DISK_GROW_PARTITION?
I'm trying to shrink my partition to the last used LCN. Has anybody used this control code?
I'm getting System Error code 87 every time in the following code:
HANDLE hDiskHandle = NULL;
        DISK_GROW_PARTITION dgp;
        DWORD dwBytesReturned = 0;
        dgp.PartitionNumber = 2;
        dgp.BytesToGrow.QuadPart = -1;
        hDiskHandle = CreateFile(_T("\\.\PhysicalDrive0"), GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, NULL, NULL);
        if (hDiskHandle == INVALID_HANDLE_VALUE) {
            int err = GetLastError();
            printf("Unable to get handle on Volume, error : %d"开发者_如何学运维, err);
        }
        if (!DeviceIoControl(
                hDiskHandle,       
                IOCTL_DISK_GROW_PARTITION,  
                &dgp,
                sizeof dgp,      
                NULL,       
                0,     
                &dwBytesReturned,  
                NULL
                )) {
            int err = GetLastError();
            printf("DeviceIoControl Failed, error : %d", err);;
        }
My hard drive has 3 partitions (C, D, E). The E: drive is practically empty.
[OP's solution converted to answer below]
It turns out my program was fine. It started working after changing access from
GENERIC_ALL
to
GENERIC_READ | GENERIC_WRITE
 加载中,请稍侯......
      
精彩评论