问题描述
WinUSB_Initialize 函数为什么会出现 INVALID_FUNCTION (0x1) 错误?这是一个来自 winusb.dll 的函数,它返回一个接口句柄.
Why does the WinUSB_Initialize function occur INVALID_FUNCTION (0x1) Error?This is a function from the winusb.dll which returns an interface handle.
我想要一个接口句柄.我已经有一个设备句柄.
I would like to get an Interface handle.I already have a Device handle.
internal struct devInfo
{
internal SafeFileHandle deviceHandle;
internal IntPtr winUsbHandle;
internal Byte bulkInPipe;
internal Byte bulkOutPipe;
internal Byte interruptInPipe;
internal Byte interruptOutPipe;
internal UInt32 devicespeed;
}
internal const Int32 FILE_ATTRIBUTE_NORMAL = 0X80;
internal const Int32 FILE_FLAG_OVERLAPPED = 0X40000000;
internal const Int32 FILE_SHARE_READ = 1;
internal const Int32 FILE_SHARE_WRITE = 2;
internal const UInt32 GENERIC_READ = 0X80000000;
internal const UInt32 GENERIC_WRITE = 0X40000000;
internal const Int32 OPEN_EXISTING = 3;
[DllImport("winusb.dll", SetLastError = true)]
internal static extern Boolean WinUsb_Initialize
(SafeFileHandle DeviceHandle,
ref IntPtr InterfaceHandle);
internal devInfo myDevInfo; // = new devInfo();
public IntPtr Get_WinUSB_handle()
{
Guid myGuid = Get_HID_GUID();
IntPtr deviceInfoSet = Get_Device_Info_Set(myGuid);
SP_DEVICE_INTERFACE_DATA MyDeviceInterfaeData = Get_Device_Interface_Data(deviceInfoSet, myGuid);
IntPtr detailDataBuffer = Get_Structure_with_Device_PathName(deviceInfoSet, ref MyDeviceInterfaeData);
string devicePathName = Get_Device_PathName(detailDataBuffer);
myDevInfo.deviceHandle= CreateFile(devicePathName,
(GENERIC_WRITE | GENERIC_READ),
FILE_SHARE_READ | FILE_SHARE_WRITE,
IntPtr.Zero,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0);
Boolean success;
success = WinUsb_Initialize(myDevInfo.deviceHandle, ref myDevInfo.winUsbHandle);
System.Console.WriteLine(Marshal.GetLastWin32Error());
System.Console.WriteLine(success);
return myDevInfo.winUsbHandle;
}
推荐答案
我相信您所连接的设备实际上并未使用 winusb.sys 作为其驱动程序之一.对于可能阅读本文的其他人,您可以通过在设备管理器中双击它,转到驱动程序"来检查设备是否使用 winusb.sys.选项卡,然后单击驱动程序详细信息".如果您在那里没有看到 winusb.sys
,那么这不是 WinUSB 设备.
I believe you are connecting to a device that is not actually using winusb.sys as one of its drivers. To other people who might read this, you can check if a device uses winusb.sys by double-clicking it in the Device Manager, going to the "Driver" tab, and clicking on "Driver Details". If you don't see winusb.sys
there then this is not a WinUSB device.
要拥有 WinUSB 设备,您需要编写一个适当的 INF 文件,然后告诉 Windows 以某种方式使用它.
To have a WinUSB device, you need to write a proper INF file and then tell Windows to use it one way or another.
您似乎正在尝试访问 HID.我会推荐 HIDAPI,而不是使用 WinUSB.
It looks like you are trying to access an HID. Instead of using WinUSB I would recommend HIDAPI.
这篇关于WinUSB_Initialize 函数发生 INVALID_FUNCTION (0x1) 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!