在C#中,我编写代码来检测串口的设备信息的到达/删除。
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
const int WM_DEVICECHANGE = 0x0219;
// System detects a new device
const int DBT_DEVICEARRIVAL = 0x8000;
// The device has been succesfully removed from the system
const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
if (msg == WM_DEVICECHANGE)
{
switch (wParam.ToInt32())
{
case DBT_DEVICEARRIVAL:
MessageBox.Show("New device added");
break;
case DBT_DEVICEREMOVECOMPLETE:
MessageBox.Show("An device has been removed from system");
break;
default:
break;
}
}
return IntPtr.Zero;
}
我在谷歌搜索,我创建了这篇文章。 http://www.codeproject.com/Articles/60579/A-USB-Library-to-Detect-USB-Devices
它完全给出了我需要编写的代码。但我必须提供一个PID和VID。
所以,我需要将我的代码与上面的代码结合起来,制作一个程序,自动显示有关设备到达/删除的信息。
我的问题是:从WndProc(IntPtr hwnd,int msg,IntPtr wParam,IntPtr lParam,ref bool处理),如何提取设备的VID和PID?