71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security;
|
|
|
|
namespace SuperMap.RealEstate.SecurityDevice
|
|
{
|
|
#region SecurityDeviceHelper
|
|
[SecuritySafeCritical]
|
|
internal class SecurityDeviceHelper
|
|
{
|
|
//public static ISecurityDevice CreateSecurityDevice()
|
|
//{
|
|
// //换设备时候,操作如下
|
|
// //1、修改UsbKeyDevice为新设备类库
|
|
// //2、引用相关类库。本范例引用 Components.UsbKey.dll
|
|
|
|
// return new UsbKeyDevice();
|
|
//}
|
|
|
|
public const int WM_DEVICECHANGE = 0x0219;
|
|
public const int DBT_DEVICEARRIVAL = 0x8000; // systemdetected a new device
|
|
public const int DBT_DEVICEREMOVECOMPLETE = 0x8004; // device is gone
|
|
public const int DEVICE_NOTIFY_WINDOW_HANDLE = 0;
|
|
public const int DEVICE_NOTIFY_SERVICE_HANDLE = 1;
|
|
public const int DBT_DEVTYP_DEVICEINTERFACE = 0x00000005; // deviceinterface class
|
|
public static Guid GUID_DEVINTERFACE_USB_DEVICE = new Guid("4D1E55B2-F16F-11CF-88CB-001111000030");
|
|
|
|
|
|
//[StructLayout(LayoutKind.Sequential)]
|
|
//public class DEV_BROADCAST_HDR
|
|
//{
|
|
// public int dbcc_size;
|
|
// public int dbcc_devicetype;
|
|
// public int dbcc_reserved;
|
|
//}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct DEV_BROADCAST_DEVICEINTERFACE
|
|
{
|
|
public int dbcc_size;
|
|
public int dbcc_devicetype;
|
|
public int dbcc_reserved;
|
|
public Guid dbcc_classguid;
|
|
public short dbcc_name;
|
|
}
|
|
|
|
//[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
//public class DEV_BROADCAST_DEVICEINTERFACE1
|
|
//{
|
|
// public int dbcc_size;
|
|
// public int dbcc_devicetype;
|
|
// public int dbcc_reserved;
|
|
// [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 16)]
|
|
// public byte[] dbcc_classguid;
|
|
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
|
|
// public char[] dbcc_name;
|
|
//}
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr NotificationFilter, Int32 Flags);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern int GetLastError();
|
|
|
|
}
|
|
#endregion
|
|
}
|