我在编码检测USB设备的时候遇到一个问题,一直解决不了。待检测的USB设备是自行设计的,可以正常工作。在程序中,我用OnUSBChange(WPARAM wParam, LPARAM lParam)函数响应WM_DEVICECHANGE消息。为了简单起见,我将代码简化如下:
LRESULT CMainFrame::OnUSBChange(WPARAM wParam, LPARAM lParam)
{
DEV_BROADCAST_HDR *pDEV = (DEV_BROADCAST_HDR*)lParam;
if (wParam == DBT_DEVICEARRIVAL)
{
AfxMessageBox("OK");
}
if (wParam == DBT_DEVICEREMOVECOMPLETE)
{
AfxMessageBox("NO");
}
return CWnd::OnDeviceChange(wParam, lParam);
} |