Win32Usb.WM_DEVICECHANGE的问题

dceacho 2016-05-19 03:59:07
代码很简单,USB设备状态变化事件里处理一些东西,
但我插拔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
...全文
179 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞天凤凰601 2016-05-19
  • 打赏
  • 举报
回复
刚才看了,你的值也是这个 你看看你的U盘,增加的盘符是不是“硬盘”的盘符,而不是“可移动存储”的盘符。 如果是,哪就不行,我编的程序,曾经碰上过这种问题,呵呵 必须是“可移动存储”,才起作用。
飞天凤凰601 2016-05-19
  • 打赏
  • 举报
回复
DEVICE_ARRIVAL=0x8000; DEVICE_REMOVECOMPLETE=0x8004; 你试试这2个值。
飞天凤凰601 2016-05-19
  • 打赏
  • 举报
回复
版主,是不是想得到U盘插入和拨出的状态?

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧