SoftKey_Win.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace NS_SoftKey_Win
  4. {
  5. /// <summary>
  6. /// Class1 µÄժҪ˵Ã÷¡£
  7. /// </summary>
  8. public class Win32
  9. {
  10. public const int WM_DEVICECHANGE = 0x0219;
  11. public const int DBT_DEVICEARRIVAL = 0x8000, // systemdetected a new device
  12. DBT_DEVICEREMOVECOMPLETE = 0x8004; // device is gone
  13. public const int DEVICE_NOTIFY_WINDOW_HANDLE = 0,
  14. DEVICE_NOTIFY_SERVICE_HANDLE = 1;
  15. public const int DBT_DEVTYP_DEVICEINTERFACE = 0x00000005; // deviceinterface class
  16. public static Guid GUID_DEVINTERFACE_USB_DEVICE = new
  17. Guid("4D1E55B2-F16F-11CF-88CB-001111000030");
  18. [StructLayout(LayoutKind.Sequential)] public class DEV_BROADCAST_HDR
  19. {
  20. public int dbcc_size;
  21. public int dbcc_devicetype;
  22. public int dbcc_reserved;
  23. }
  24. [StructLayout(LayoutKind.Sequential)] public class
  25. DEV_BROADCAST_DEVICEINTERFACE
  26. {
  27. public int dbcc_size;
  28. public int dbcc_devicetype;
  29. public int dbcc_reserved;
  30. public Guid dbcc_classguid;
  31. public short dbcc_name;
  32. }
  33. [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
  34. public class DEV_BROADCAST_DEVICEINTERFACE1
  35. {
  36. public int dbcc_size;
  37. public int dbcc_devicetype;
  38. public int dbcc_reserved;
  39. [MarshalAs(UnmanagedType.ByValArray, ArraySubType=UnmanagedType.U1,
  40. SizeConst=16)] public byte [] dbcc_classguid;
  41. [MarshalAs(UnmanagedType.ByValArray, SizeConst=128)] public char []
  42. dbcc_name;
  43. }
  44. [DllImport("user32.dll", SetLastError=true)] public static extern
  45. IntPtr RegisterDeviceNotification( IntPtr hRecipient, IntPtr
  46. NotificationFilter, Int32 Flags);
  47. [DllImport("kernel32.dll")] public static extern int GetLastError();
  48. }
  49. }