c#通过调用api访问usb设备
其中调用DeviceIoControl函数时总是返回错误号87,意味着参数错误,请问是什么问题呢?谢谢,代码如下
    [DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern bool DeviceIoControl(
            IntPtr hDevice,
            uint dwIoControlCode,
            ref long InBuffer,
            int nInBufferSize,
            ref long OutBuffer,
            int nOutBufferSize,
            ref int pBytesReturned,
            ref NativeOverlapped lpOverlapped); private long ResetPort(IntPtr hDevice)
    {
      int outByte = 0;
      System.Threading.NativeOverlapped overlapped = new System.Threading.NativeOverlapped();      overlapped.InternalLow = IntPtr.Zero;
      overlapped.InternalHigh = IntPtr.Zero;
      overlapped.OffsetLow = 0;
      overlapped.OffsetHigh = 0;
      overlapped.EventHandle = CreateEvent(IntPtr.Zero, true, false, null);      long inbuffer = 0;
      DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT, ref inbuffer, 0, ref inbuffer, 0, ref outByte,     ref overlapped);      return Marshal.GetLastWin32Error() ;
    }

解决方案 »

  1.   

    参数转化:http://blog.csdn.net/carl2380/archive/2010/01/21/5219793.aspx
      

  2.   

    参数转化没有问题,都是http://pinvoke.net/default.aspx/kernel32/DeviceIoControl.html上的标准类型了
      

  3.   

    应该将API原始参数贴出来,才能对照
      

  4.   

    WINAPI
    DeviceIoControl(
    __in        HANDLE hDevice,
    __in        DWORD dwIoControlCode,
    __in_bcount_opt(nInBufferSize) LPVOID lpInBuffer,
    __in        DWORD nInBufferSize,
    __out_bcount_part_opt(nOutBufferSize, *lpBytesReturned) LPVOID lpOutBuffer,
    __in        DWORD nOutBufferSize,
    __out_opt   LPDWORD lpBytesReturned,
    __inout_opt LPOVERLAPPED lpOverlapped
    );WINBASEAPI
    附上原始api
      

  5.   

    [DllImport("kernel32.dll", EntryPoint="DeviceIoControl")]
    public static extern int DeviceIoControl (
        int hDevice,
        int dwIoControlCode,
        ref int lpInBuffer,
        int nInBufferSize,
        ref int lpOutBuffer,
        int nOutBufferSize,
        ref int lpBytesReturned,
        ref OVERLAPPED lpOverlapped
    );http://stackoverflow.com/questions/1067216/calling-deviceiocontrol-from-c-with-ioctl-dvd-control-codes