网上对USB设备的回答实在太少了 我想检测指定USB设备的拔插事件,当USB装好驱动后 会有设备指定的PID 和VID 我就是通过这个进行访问设备的 但是设备拔插事件怎么处理呢 是不是用个Timer去实时检测?还是有其他什么办法 ?
------解决方案--------------------------------------------------------
七八年前的代码了,处理自己的USB设备的拔插.
你看下能用上不?
//---------------------------------------------------------------------------
//#include <Dbt.h>
void __fastcall TMainForm::WndProc(TMessage &Message)
{
if (Message.Msg == WM_DEVICECHANGE)
{
bool bPnP_Arrival=false;
bool bPnP_Removal=false;
//bool bPnP_DevNodeChange;
DEV_BROADCAST_DEVICEINTERFACE *bcastHdr;
if (Message.WParam == DBT_DEVICEARRIVAL)
{
bcastHdr = (DEV_BROADCAST_DEVICEINTERFACE*) Message.LParam;
if (bcastHdr->dbcc_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
if(GUIDToString(bcastHdr->dbcc_classguid)==GUIDToString(CYUSBDRV_GUID))
bPnP_Arrival = true;
}
//else if (Message.WParam == DBT_DEVNODES_CHANGED)
//{
// bPnP_DevNodeChange = true;
//}
else if (Message.WParam == DBT_DEVICEREMOVECOMPLETE)
{
bcastHdr = (DEV_BROADCAST_DEVICEINTERFACE*) Message.LParam;
if (bcastHdr->dbcc_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
if(GUIDToString(bcastHdr->dbcc_classguid)==GUIDToString(CYUSBDRV_GUID))
bPnP_Removal = true;
}
if (bPnP_Removal)
{
Sleep(10);
ResetInfo(false);
}
if (bPnP_Arrival)
{
ResetInfo(true);
}
}
TForm::WndProc(Message);
}
//---------------------------------------------------------------------------
拔插...拔插...拔插...拔插...好爽...