locked
How can I get disk information via DeviceIoControlSync() API?

    Question

  • Hi all,

    I'm trying to use DeviceIoControlSync() API, but have some problem in consumer preview version.

    Following code snips can be compiled in "Win 8 Developer Preview", but can not get any result (WinRT DLL; get access deny error).


    // Get Device Access Instance
    DWORD dword = 0;
    IDeviceIoControl *pDeviceIoControl;
    ICreateDeviceAccessAsync *pDeviceAccess;
    HRESULT hr = CreateDeviceAccessInstance(IID_IDeviceIoControl, 
    											L"\\\\.\\PhysicalDrive0", 
    											0, 
    											&pDeviceAccess);
    
        if (FAILED(hr)) {
            return -1;
        }
    
        hr = pDeviceAccess->Start();
    
        if (SUCCEEDED(hr)) {
            hr = pDeviceAccess->Wait(INFINITE);
        }
        else {
            return -2;
        }
    
        if (SUCCEEDED(hr)) {
            hr = pDeviceAccess->GetResult(reinterpret_cast<void **>(&pDeviceIoControl));
        }
        else {
    	return -3;
        }
    
        pDeviceAccess->Release();
    
        DISK_GEOMETRY DG;
    	
        // Set DeviceIoControlSync
        hr = pDeviceIoControl->DeviceIoControlSync(
                             IOCTL_DISK_GET_DRIVE_GEOMETRY,
                             NULL,
                             0,
                             (UCHAR *)&DG,
                             sizeof(DG),
                             &dword
                             );
    
    
    	return hr;

    So, I try the same code in "Win 8 Consumer Preview" this time.

    Unfortunately, I get compiler error first.

    After debugging,

    1. The number of parameter changes (IID_IDeviceIoControl).

    HRESULT hr = CreateDeviceAccessInstance(L"\\\\.\\PhysicalDrive0", 
    											0, 
    											&pDeviceAccess);

    and

    hr = pDeviceAccess->GetResult(IID_PPV_ARGS(&pDeviceIoControl));

    2. There is no Start() method in ICreateDeviceAccessAsync.

    3. I don't know why I cannot use "DISK_GEOMETRY". I already included winioctl.h and can find the struct by pressing F12.

    So, my question is.

    How can I use device IO control APIs to get disk information?

    I use the same way in win 7 desktop, and it works.

    Thanks a lot!

    Friday, March 9, 2012 8:38 AM

Answers

All replies