Answered by:
VB code to list all Webcams or video capture devices

Question
-
I am trying to add the ability to select a camera to my program
to start with I need to list the currently installed devices in a drop down menu much like what is used in MSN's webcam selection but the only thing that I can find that comes close is
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _ (ByVal wDriverIndex As Short, _ ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _ ByVal cbVer As Integer) As Boolean
This, even with 4 different webcams installed, returns "Windows WDM image capture"
Tuesday, January 19, 2010 4:00 AM
Answers
-
The code in the last answer of this blog http://bytes.com/topic/visual-basic-net/answers/438946-how-connect-camera-my-vb-net-app may help
In order to connect to differents capture devices, you must change the numbers in the line: SendMessage(HWnd, WM_CAP_DRIVER_CONNECT, 0, 0)
Good Luck !Wednesday, January 20, 2010 5:39 AM -
Add a reference to your program for Microsoft Windows Image Acquisition Library v2.0, which is file Interop.WIA.dll. Use code like this to enumerate the devices. You may be able to filter out those that aren't relevant to your task using a device property.
Private Sub cmdDevices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDevices.Click DeviceManager1 = New DeviceManager lbxDevices.Items.Clear() For I As Integer = 1 To DeviceManager1.DeviceInfos.Count lbxDevices.Items.Add(DeviceManager1.DeviceInfos(I).Properties("Name").Value) Next If DeviceManager1.DeviceInfos.Count > 0 Then lbxDevices.SelectedIndex = 0 End If End Sub
Wednesday, January 20, 2010 5:51 AM -
If the source you want is HD the it maybe protected by HDCP copy protection . It that case on any other device that is not HDCP compliant you will only get a black screen .
Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
Please format the code in your posts with thebutton . Makes it easier to read .
- Marked as answer by Chao Kuo Monday, January 25, 2010 5:59 AM
Friday, January 22, 2010 1:36 AM
All replies
-
If nobody has a more complete answer,
Have a look in this,
http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx
WMI is almost forever used in those nice pages which show you everything from your computer.
Success
CorTuesday, January 19, 2010 5:51 AM -
Now the question is what should I query the system to get my webcams.Tuesday, January 19, 2010 2:19 PM
-
The code in the last answer of this blog http://bytes.com/topic/visual-basic-net/answers/438946-how-connect-camera-my-vb-net-app may help
In order to connect to differents capture devices, you must change the numbers in the line: SendMessage(HWnd, WM_CAP_DRIVER_CONNECT, 0, 0)
Good Luck !Wednesday, January 20, 2010 5:39 AM -
Add a reference to your program for Microsoft Windows Image Acquisition Library v2.0, which is file Interop.WIA.dll. Use code like this to enumerate the devices. You may be able to filter out those that aren't relevant to your task using a device property.
Private Sub cmdDevices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDevices.Click DeviceManager1 = New DeviceManager lbxDevices.Items.Clear() For I As Integer = 1 To DeviceManager1.DeviceInfos.Count lbxDevices.Items.Add(DeviceManager1.DeviceInfos(I).Properties("Name").Value) Next If DeviceManager1.DeviceInfos.Count > 0 Then lbxDevices.SelectedIndex = 0 End If End Sub
Wednesday, January 20, 2010 5:51 AM -
I have already tried the connect to driver to change the video source but it only changes capture drivers for me because if I change the first 0 to anything else I get a blank screen.
Thanks Acamar you sent me in the right direction it seems even though I didn't use your code. I used this guys code to get a full list of all my devices http://www.codeproject.com/KB/system/GetNonWorkingDevicesVbNet.aspx
but now I need to filter based on Device Categories "Imaging.Webcam"
any ideas?Friday, January 22, 2010 12:25 AM -
If the source you want is HD the it maybe protected by HDCP copy protection . It that case on any other device that is not HDCP compliant you will only get a black screen .
Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
Please format the code in your posts with thebutton . Makes it easier to read .
- Marked as answer by Chao Kuo Monday, January 25, 2010 5:59 AM
Friday, January 22, 2010 1:36 AM -
Thanks for the great answers guys but I found what I needed using the directshow.net library helper function
hr = devEnum.CreateClassEnumerator FilterCategory.VideoInputDevice, classEnum, 0) Debug.WriteLine("Create an enumerator for the video capture devices : " & DsError.GetErrorText(hr))
Tuesday, February 23, 2010 1:57 AM -
Hey guys,
I have the same problem. I just want to know whether you(Powmax) found
a solution yet. If yes, I 'd be happy if you can send me the source code or
some snippet...
Best regards
lwag98
Thursday, May 31, 2012 5:36 PM -
If your using the directshow.net wrapper then my last post will be most useful.
Sorry but I trashed the code for this project.
Thursday, May 31, 2012 5:41 PM -
Hey Powmax,
i've integrated the directshow.lib, but what type of
var is hr?
Saturday, June 2, 2012 9:05 PM