Re: Checking if USB device is plugged in
- From: "andrew queisser" <andrewdotqueisser@xxxxxx>
- Date: Fri, 10 Nov 2006 16:52:33 GMT
"beaker" <randomstuff@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OxQQ%23JMBHHA.1012@xxxxxxxxxxxxxxxxxxxxxxx
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/archive291-2004-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]
.
- Follow-Ups:
- Re: Checking if USB device is plugged in
- From: beaker
- Re: Checking if USB device is plugged in
- References:
- Checking if USB device is plugged in
- From: beaker
- Checking if USB device is plugged in
- Prev by Date: Re: GPU Processor Abstraction...
- Next by Date: Reading Excel dates into C# come out as "weird" ints - help?
- Previous by thread: Checking if USB device is plugged in
- Next by thread: Re: Checking if USB device is plugged in
- Index(es):