当前位置:编程学习 > C#/ASP.NET >>

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#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,