Can't get the bytesReturned value when calling DeviceIoControlSync

Respondida Can't get the bytesReturned value when calling DeviceIoControlSync

  • 13 April 2012 1:52
     
      Memiliki Kode

    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!


Semua Balasan

  • 13 April 2012 2:40
     
     

    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.

  • 22 April 2012 1:25
    Moderator
     
     

    Rojer,

    Were you able to get this resolved?

    Best Wishes - Eric

  • 23 April 2012 3:41
     
     

    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.


  • 09 Mei 2012 21:08
    Moderator
     
     

    Rojer,

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

    Best Wishes - Eric 

  • 09 Mei 2012 23:25
    Moderator
     
     Jawab

    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

  • 10 Mei 2012 0:54
     
     
    Thank you, Eric. I'll double check that.
  • 10 Mei 2012 1:37
    Moderator
     
     

    Let me know.  That should be it though.

    Best Wishes - Eric