代码很简单,USB设备状态变化事件里处理一些东西,
但本人插拔USB后这里的参数值m.WParam值为0x07 不是Win32Usb.WM_DEVICECHANGE也不是Win32Usb.DEVICE_REMOVECOMPLETE: Win32USb.cs里也没找到0x07代表什么
但本人插拔USB后这里的参数值m.WParam值为0x07 不是Win32Usb.WM_DEVICECHANGE也不是Win32Usb.DEVICE_REMOVECOMPLETE: Win32USb.cs里也没找到0x07代表什么
public void ParseMessages(ref Message m) { if (m.Msg == Win32Usb.WM_DEVICECHANGE) // we got a device change message! A USB device was inserted or removed { switch (m.WParam.ToInt32()) // Check the W parameter to see if a device was inserted or removed { case Win32Usb.DEVICE_ARRIVAL: // inserted if (OnDeviceArrived != null) { OnDeviceArrived(this, new System.EventArgs()); CheckDevicePresent(); } break; case Win32Usb.DEVICE_REMOVECOMPLETE: // removed if (OnDeviceRemoved != null) { OnDeviceRemoved(this, new System.EventArgs()); CheckDevicePresent(); } break; } } }
Win32USB.cs里各值的定义
#region Constants /// <summary>Windows message sent when a device is inserted or removed</summary> public const int WM_DEVICECHANGE = 0x0219; /// <summary>WParam for above : A device was inserted</summary> public const int DEVICE_ARRIVAL = 0x8000; /// <summary>WParam for above : A device was removed</summary> public const int DEVICE_REMOVECOMPLETE = 0x8004; /// <summary>Used in SetupDiClassDevs to get devices present in the system</summary> protected const int DIGCF_PRESENT = 0x02; /// <summary>Used in SetupDiClassDevs to get device interface details</summary> protected const int DIGCF_DEVICEINTERFACE = 0x10; /// <summary>Used when registering for device insert/remove messages : specifies the type of device</summary> protected const int DEVTYP_DEVICEINTERFACE = 0x05; /// <summary>Used when registering for device insert/remove messages : we"re giving the API call a window handle</summary> protected const int DEVICE_NOTIFY_WINDOW_HANDLE = 0; /// <summary>Purges Win32 transmit buffer by aborting the current transmission.</summary> protected const uint PURGE_TXABORT = 0x01; /// <summary>Purges Win32 receive buffer by aborting the current receive.</summary> protected const uint PURGE_RXABORT = 0x02; /// <summary>Purges Win32 transmit buffer by clearing it.</summary> protected const uint PURGE_TXCLEAR = 0x04; /// <summary>Purges Win32 receive buffer by clearing it.</summary> protected const uint PURGE_RXCLEAR = 0x08; /// <summary>CreateFile : Open file for read</summary> protected const uint GENERIC_READ = 0x80000000; /// <summary>CreateFile : Open file for write</summary> protected const uint GENERIC_WRITE = 0x40000000; /// <summary>CreateFile : file share for write</summary> protected const uint FILE_SHARE_WRITE = 0x2; /// <summary>CreateFile : file share for read</summary> protected const uint FILE_SHARE_READ = 0x1; /// <summary>CreateFile : Open handle for overlapped operations</summary> protected const uint FILE_FLAG_OVERLAPPED = 0x40000000; /// <summary>CreateFile : Resource to be "created" must exist</summary> protected const uint OPEN_EXISTING = 3; /// <summary>CreateFile : Resource will be "created" or existing will be used</summary> protected const uint OPEN_ALWAYS = 4; /// <summary>ReadFile/WriteFile : Overlapped operation is incomplete.</summary> protected const uint ERROR_IO_PENDING = 997; /// <summary>Infinite timeout</summary> protected const uint INFINITE = 0xFFFFFFFF; /// <summary>Simple representation of a null handle : a closed stream will get this handle. Note it is public for comparison by higher level classes.</summary> public static IntPtr NullHandle = IntPtr.Zero; /// <summary>Simple representation of the handle returned when CreateFile fails.</summary> protected static IntPtr InvalidHandleValue = new IntPtr(-1); #endregion
解决方案
40
刚才看了,你的值也是这个
你看看你的U盘,增加的盘符是不是“硬盘”的盘符,而不是“可移动存储”的盘符。
假如是,哪就不行,本人编的程序,曾经碰上过这种问题,呵呵
必须是“可移动存储”,才起作用。
你看看你的U盘,增加的盘符是不是“硬盘”的盘符,而不是“可移动存储”的盘符。
假如是,哪就不行,本人编的程序,曾经碰上过这种问题,呵呵
必须是“可移动存储”,才起作用。