locked
Can't get the bytesReturned value when calling DeviceIoControlSync

    Question

  • Hi All,

    Here I met with a strange problem:

    In metro, when I trying to using DeviceIoControlSync to talk with the driver, bytesReturned always return 0. And the lpOutBuffer has already be filled with desired data by the driver. Here's my operations.

    first open the driver


            hr = CreateDeviceAccessInstance(L"\\\\?\\usb#vid_0cf3&pid_3006#6&2f1d3603&0&4#{7cec675d-0131-4194-9a30-49907e9e6c77}",
                                            GENERIC_READ | GENERIC_WRITE,
                                            &access);
            if(FAILED(hr))
            {
                throw hr;
            }
            hr = access->Wait(INFINITE);
            if(FAILED(hr))
            {
                throw hr;
            }
            hr = access->GetResult(IID_PPV_ARGS(&deviceControl));

    then access the driver using ioctl

        DWORD bytesReturned;
        hr = deviceControl->DeviceIoControlSync(IOCTL_READ_DATA, NULL, 0,  (PUCHAR)lpOutBuffer, dwOutSize, &bytesReturned );
        if(bytesReturned == 0)
        {
            return E_FAIL;
        };

    I've check with my driver and am sure that the driver has set the iostatus.information correctly. And I've tried using old IOCtl methods in desktop, like  

     bRet = DeviceIoControl(hDevice, IOCTL_READ_DATA, NULL, 0 , pData, 1000, &dwOutputSize, NULL);

    I can successfully get the dwOutputSize.

    Then again I tried the DeviceIoControlSync method in desktop, it also fails to get the bytesReturned.

    So does anyone has idea about this problem?

    Thanks!


    • Edited by Roger Tang Friday, April 13, 2012 1:54 AM
    Friday, April 13, 2012 1:52 AM

Answers

All replies

  • additional information:

    1.the driver is a debug version, and if i open the dbgview to observe the driver trace, some times i can get the right bytesReturned value. :(

    2.I've both tried on OS version 8250/8301 and got the same result.

    Friday, April 13, 2012 2:40 AM
  • Rojer,

    Were you able to get this resolved?

    Best Wishes - Eric

    Sunday, April 22, 2012 1:25 AM
    Moderator
  • Rojer,

    Were you able to get this resolved?

    Best Wishes - Eric

    Hi Eric,

    Thank you for the reply. But still not resolved :(.  To avoid this, I have to point out the output data size in the first DWORD of lpOutputBuffer.


    • Edited by Roger Tang Monday, April 23, 2012 3:41 AM
    Monday, April 23, 2012 3:41 AM
  • Rojer,

    I have looked at your code and it looks good.  I am still researching this for you.

    Best Wishes - Eric 

    Wednesday, May 09, 2012 9:08 PM
    Moderator
  • Roger,

    It does seem to work correctly here.  Could you ensure you are returning STATUS_SUCCESS from your driver code?  Perhaps by checking the return value.

    Best Wishes - Eric

    Wednesday, May 09, 2012 11:25 PM
    Moderator
  • Thank you, Eric. I'll double check that.
    Thursday, May 10, 2012 12:54 AM
  • Let me know.  That should be it though.

    Best Wishes - Eric

    Thursday, May 10, 2012 1:37 AM
    Moderator