"beaker" <ra*********@notrealcompanyIhope.comwrote in message
news:Ox****************@TK2MSFTNGP04.phx.gbl...
>
Hi,
I'm looking for a way of checking whether a specific USB device (a webcam)
is plugged in. I have the Vendor and Product ID numbers for the device.
I found an article (http://www.vsj.co.uk/articles/display.asp?id=600) with
code sample that does the trick for human input devices (mouse, keyboard,
...) but am struggling for my webcam.
Any help appreciated, thanks.
Gary
Gary,
It's easy outside of .NET if you handle the WM_DEVICECHANGE message. Below
is a snippet of a MFC program that does that. It shouldn't be hard to map
this to .NET, here's a discussion of just that, I haven't tried it myself:
http://www.codecomments.com/archive2...-4-185490.html
My MFC (edited) code snippet:
BOOL CConfigWinDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
{
DEV_BROADCAST_DEVICEINTERFACE *devInterface;
DEV_BROADCAST_HDR *brHeader = (DEV_BROADCAST_HDR *)dwData;
switch (nEventType)
{
case (DBT_DEVICEARRIVAL):
if (brHeader && brHeader->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
devInterface = (DEV_BROADCAST_DEVICEINTERFACE *)brHeader;
if (strstr(strupr(devInterface->dbcc_name), "VID_0403&PID_6006"))
{
// my device plugged in
// do something cool
}
else
{
// some other device plugged in
}
}
else
{
// unknown device plugged in
}
}
break;
// other cases
}
[snip]