Exemplo n.º 1
0
        private void InitializeDeviceNotification()
        {
            NativeApi.DEV_BROADCAST_DEVICEINTERFACE DevBroadcastDeviceInterface = new NativeApi.DEV_BROADCAST_DEVICEINTERFACE();

            try
            {
                IntPtr DevBroadcastDeviceInterfaceBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(DevBroadcastDeviceInterface));

                DevBroadcastDeviceInterface.dbcc_size       = Marshal.SizeOf(DevBroadcastDeviceInterface);
                DevBroadcastDeviceInterface.dbcc_devicetype = NativeApi.DBT_DEVTYP_DEVICEINTERFACE;
                DevBroadcastDeviceInterface.dbcc_reserved   = 0;
                DevBroadcastDeviceInterface.dbcc_classguid  = this.HidGuid;

                Marshal.StructureToPtr(DevBroadcastDeviceInterface, DevBroadcastDeviceInterfaceBuffer, true);

                deviceNotificationHandle = NativeApi.RegisterDeviceNotification(this.Handle, DevBroadcastDeviceInterfaceBuffer, NativeApi.DEVICE_NOTIFY_WINDOW_HANDLE);

                Marshal.FreeHGlobal(DevBroadcastDeviceInterfaceBuffer);

                if (deviceNotificationHandle.Equals(IntPtr.Zero))
                {
                    throw new Exception();
                }
            }
            catch
            {
                EmitLogMessage(HidLogMessageType.Warning, "Registering for Device Notifications failed!");
            }
        }
Exemplo n.º 2
0
        private void InitializeDeviceNotification()
        {
            NativeApi.DEV_BROADCAST_DEVICEINTERFACE DevBroadcastDeviceInterface = new NativeApi.DEV_BROADCAST_DEVICEINTERFACE();

            try
            {

                IntPtr DevBroadcastDeviceInterfaceBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(DevBroadcastDeviceInterface));

                DevBroadcastDeviceInterface.dbcc_size = Marshal.SizeOf(DevBroadcastDeviceInterface);
                DevBroadcastDeviceInterface.dbcc_devicetype = NativeApi.DBT_DEVTYP_DEVICEINTERFACE;
                DevBroadcastDeviceInterface.dbcc_reserved = 0;
                DevBroadcastDeviceInterface.dbcc_classguid = this.HidGuid;

                Marshal.StructureToPtr(DevBroadcastDeviceInterface, DevBroadcastDeviceInterfaceBuffer, true);

                deviceNotificationHandle = NativeApi.RegisterDeviceNotification(this.Handle, DevBroadcastDeviceInterfaceBuffer, NativeApi.DEVICE_NOTIFY_WINDOW_HANDLE);

                Marshal.FreeHGlobal(DevBroadcastDeviceInterfaceBuffer);

                if (deviceNotificationHandle.Equals(IntPtr.Zero)) throw new Exception();
            }
            catch
            {
                EmitLogMessage(HidLogMessageType.Warning, "Registering for Device Notifications failed!");
            }
        }