ISO file will not open when using Windows Virtual Disk Service, error code 50: ERROR_NOT_SUPPORTED

StackOverflow https://stackoverflow.com/questions/23688648

문제

I am trying to load an ISO file in my program and mount it by using the Windows 8.1 Virtual Disk service. Before I load the ISO I load a VHD file on which a game resides. then I want to mount the ISO for the game to work (the ISO resides on the VHD but the problem also occurs when the ISO resides within the program directory).

Now, I don't know why the operation is "NOT SUPPORTED" (error code 50), but I know that windows is able to mount ISO's because when I double click them, they get mounted by windows Explorer (and it obviously uses the Virtual Disk Service, as the KB of the virtual service states that ISO mounting is supported from windows 7 and later).

Now, how I try to load the iso file is this:

GUID GUID_TEST = { 12345678 - 1234 - 5678 - 1234 - 000000000000 };

//convert string to wstring
std::wstring s2ws(const std::string& str)
{
    typedef std::codecvt_utf8<wchar_t> convert_typeX;
    std::wstring_convert<convert_typeX, wchar_t> converterX;

    return converterX.from_bytes(str);
}

DWORD OpenISO(const char* isoFilePath, HANDLE *handle)
{
    VIRTUAL_STORAGE_TYPE storageType =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_ISO,
        GUID_TEST
    };

    OPEN_VIRTUAL_DISK_PARAMETERS parameters =
    {
        OPEN_VIRTUAL_DISK_VERSION_1
    };

    return ::OpenVirtualDisk(
        &storageType,
        s2ws(std::string(isoFilePath)).c_str(),
        VIRTUAL_DISK_ACCESS_READ,
        OPEN_VIRTUAL_DISK_FLAG_NONE,
        &parameters,
        handle);
}

void main()
{
    //load VHD here, do some program setup, etc etc
    //then load iso:

    //makesure VHD is mounted and ready
    UINT dtype = GetDriveTypeA(Config.MountPoint.c_str());
    while (dtype == 1 || dtype == 0)
    {
        dtype = GetDriveTypeA(Config.MountPoint.c_str());
        Sleep(10);
    }
    std::cout << "OK" << std::endl;
    //just a bit more waiting to be sure it is really loaded correctly
    Sleep(2500);
    //now load the iso our game needs to run
    HANDLE  isohandle;
    if (FileExists(Config.ISO_location.c_str()))
    {
        std::cout << "Mounting ISO... " << std::flush;
        if (OpenISO(Config.ISO_location.c_str(), &isohandle) == ERROR_SUCCESS)
        {
            if (AttachVirtualDisk(isohandle, NULL, ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY, 0, 0, NULL) == ERROR_SUCCESS)
            {
                std::cout << "ISO mounted.\r\n";
            }
            else
            {
                std::cout << "ISO NOT mounted (" << GetLastError() << ").\r\n";
            }
        }
        else
        {
            std::cout << "Cannot open ISO file, skipping (" << GetLastError() << ").\r\n";
        }
    }
    //launch the game process here
    //wait til game ends
    //cleanup
    //shutdown
}

I always get the message ISO NOT mounted(50). When replacing GUID_TEST with the microsoft default guid I get ISO NOT mounted(0), Error code 0 should indicate succes, but somehow the ISO does not appear in disk management. What is wrong here? Why won't my ISO be mounted programaticly while explorer can?

I admit I don't exactly know how to mount an ISO, but I do mount a VHD this way:

DWORD OpenVDisk(const char* virtualDiskFilePath, HANDLE *handle)
{
    VIRTUAL_STORAGE_TYPE storageType =
    {
        VIRTUAL_STORAGE_TYPE_DEVICE_VHD,
        VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
    };

    OPEN_VIRTUAL_DISK_PARAMETERS parameters =
    {
        OPEN_VIRTUAL_DISK_VERSION_1
    };

    parameters.Version1.RWDepth = 1024;

    return ::OpenVirtualDisk(
        &storageType,
        s2ws(std::string(virtualDiskFilePath)).c_str(),
        VIRTUAL_DISK_ACCESS_ALL,
        OPEN_VIRTUAL_DISK_FLAG_NONE,
        &parameters,
        handle);
}

    //somewhere else
HANDLE  handle;
DWORD   result;
ULONG   bytesUsed;

result = OpenVDisk(Config.VHD_location.c_str(), &handle);
if (result != ERROR_SUCCESS)
{
    std::cout << "Unable to open virtual disk '" << Config.VHD_location << "'" << std::endl;
    return (int)pressanykey("Hit any key to quit the application\r\n");
}
std::cout << "OK" << std::endl;
std::cout << "Attaching Game Disk..." << std::flush;
result = AttachVirtualDisk(handle, NULL, ATTACH_VIRTUAL_DISK_FLAG_NO_DRIVE_LETTER, 0, 0, NULL);
if (result != ERROR_SUCCESS)
{
    std::cout << "Unable to attach virtual disk (did you forget to run this program with administrative rights? -- " << GetLastError() << ")" << std::endl;
    return (int)pressanykey("Hit any key to quit the application\r\n");
}
std::cout << "OK" << std::endl;

and the VHD mounting works. This makes me really wonder why ISO does not.

도움이 되었습니까?

해결책

The solution is to make sure the ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME flag is specified, then also make sure the ISO file size is a multiple of 2048 bytes. Now it works.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top