c# winform 怎么把设备注册到窗口
我需要检测hid设备插拔信息,
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr NotificationFilter, uint Flags);
[StructLayout(LayoutKind.Explicit)]
private struct DevBroadcastDeviceInterfaceBuffer
{
public DevBroadcastDeviceInterfaceBuffer(Int32 deviceType)
{
dbch_size = Marshal.SizeOf(typeof(DevBroadcastDeviceInterfaceBuffer));
dbch_devicetype = deviceType;
dbch_reserved = 0;
}
[FieldOffset(0)]
public Int32 dbch_size;
[FieldOffset(4)]
public Int32 dbch_devicetype;
[FieldOffset(8)]
public Int32 dbch_reserved;
}
//注册设备变化消息到指定窗口
//返回值:成功,对应的句柄。失败,0
static public IntPtr RegiseterUsbHidDeviceNotificationToWindow(IntPtr hWndToRecieveNotification)
{
IntPtr mem = IntPtr.Zero;
mem = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DevBroadcastDeviceInterfaceBuffer)));
Marshal.StructureToPtr(new DevBroadcastDeviceInterfaceBuffer(5), mem, false);
return RegisterDeviceNotification(hWndToRecieveNotification, mem, DEVICE_NOTIFY_WINDOW_HANDLE);
}
注册后检测不到信息 , 这里面的注册是少了什么东西呢,谢谢!
--------------------编程问答--------------------
有知道的吗。
补充:.NET技术 , C#