Q:

Access Violation with FindVolumeClose()

In the following function, when I hit the FindVolumeClose() line, I always get the error outlined below.  Any ideas why this happens?
Unhandled exception at 0x11000000 in BootFixFFS.exe: 0xC0000005: Access violation (parameters: 0x00000008).
char buffer[MAX_PATH];

HANDLE hVol = FindFirstVolume(buffer, MAX_PATH);

if (hVol == INVALID_HANDLE_VALUE) {
    std::cout << "No volumes found\n.";

    return FALSE;
}

std::string strVol = buffer;

strVol.pop_back();

HANDLE hPart = CreateFile(strVol.c_str(), 0, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if (hPart == INVALID_HANDLE_VALUE) {
    FindVolumeClose(hVol);

    std::cout << "Couldn't create file: " << GetLastError() << "\n";

    return FALSE;
}

int numPartitions = 8;

DWORD dwDliSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) + numPartitions * sizeof(PARTITION_INFORMATION_EX);

DRIVE_LAYOUT_INFORMATION_EX *dli = (DRIVE_LAYOUT_INFORMATION_EX*) new BYTE[dwDliSize];

DWORD dwSize;

ZeroMemory(&dli, sizeof(dli));

BOOL bSuccess = DeviceIoControl(hPart, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, &dli, dwDliSize, &dwSize, NULL);

CloseHandle(hPart);

FindVolumeClose(hVol);

if (bSuccess == FALSE) {
    std::cout << "Couldn't get device information: " << GetLastError() << "\n";

    return FALSE;
}   

return TRUE;

A:

It seems to me that ZeroMemory(&dli, sizeof(dli)) is not doing what you want it to do. It erases the address from dli, instead of zeroing the content of the byte array. Maybe ZeroMemory(dli, dwDliSize) is what you meant?
Also, the more serious error is using &dli when calling DeviceIoControl. You are basically overwriting your entire stack, and destroying the local variables.

