none
Selecting a particular webcam

    Question

  •  

    Hi all,

     

    Me again.

     

    I wrote some software that use the AVICAP32.dll to do a spot of video capture.

     

    All was going well till they went and bought a laptop with a built in webcam.  Now my software picks one a random and uses that for the video (somewhat annoying to say the least) - SO -

     

    Can anyone tell me how to pick a camera to use,  I suspect it is related to  DVM_DIALOG but my experiments have not been too sucessful.

     

    Any help would be appreciated,

     

    Thanks

     

    Steve

    Thursday, May 24, 2007 9:45 AM

Answers

  • JaJaPuppy,

     

    Nice meeting you again! Some devices cannot provide preview and capture at the same time unless you are capturing at half the frame rate or only capturing one field. Experiment in graphedit to make sure that this works for your device: if not, insert a smart tee on the capture pin and use that for the render output.

     

    Accroding to your question this time, I would like to provide you the WinCE WebCam. Please take a look at the following articles on the issue:

     

    Windows CE .NET WebCam, Part 1

    http://msdn2.microsoft.com/en-us/library/aa459161.aspx

     

    Windows CE .NET WebCam, Part 2

    http://msdn2.microsoft.com/en-us/library/aa459164.aspx

     

    Hope that can take you some ideas. :-)

    Wednesday, May 30, 2007 5:45 AM
  •  

    Have ever read this article below?

     

    Teach Your Old Web Cam New Tricks: Use Video Captures in Your .NET Applications

    http://www.devx.com/dotnet/Article/30375?type=kbArticle&trk=MSCP

     

    I hope the article can give you more helps. :-)

    Wednesday, May 30, 2007 9:05 AM
  • You can send a windows message to the video device handler that will activate a Video Source dialog that typically allows you to select which of the multiple cameras being serviced by the handler to use.  The message ID is: WM_CAP_DLG_VIDEOSOURCE.  The problem with this approach is that it requires user interaction, for example, you can't program the application to always select the second webcam.  If you don't mind a user dialog solution, the WM_CAP_DLG_VIDEOSOURCE approach should work fine.

     

    Let me know if you want sample code.

     

    Randy

     

    Tuesday, October 23, 2007 3:46 PM

All replies

  • JaJaPuppy,

     

    Nice meeting you again! Some devices cannot provide preview and capture at the same time unless you are capturing at half the frame rate or only capturing one field. Experiment in graphedit to make sure that this works for your device: if not, insert a smart tee on the capture pin and use that for the render output.

     

    Accroding to your question this time, I would like to provide you the WinCE WebCam. Please take a look at the following articles on the issue:

     

    Windows CE .NET WebCam, Part 1

    http://msdn2.microsoft.com/en-us/library/aa459161.aspx

     

    Windows CE .NET WebCam, Part 2

    http://msdn2.microsoft.com/en-us/library/aa459164.aspx

     

    Hope that can take you some ideas. :-)

    Wednesday, May 30, 2007 5:45 AM
  • Hi again Bruno,

     

    Thanks for your reply.

     

    It has given me some ideas for a future project :0)

     

    Unfortunatly it hasnt helped here (although having re-read my question that may be my fault - the description wasnt very clear!)

     

    My code uses AVICap32.dll directly.

     

    What it does is selects the default camera (which was fine when they only had the one - a microsoft Lifecam VX-6000).

     

    The vidoe is "bound" to a picture box that shows the full image.  (it is a winforms application).  This is shown in real time.  To capture the image we have a seperate picture box that is the size of the image we want to capture (in this case a passport photo).  A timer is used to to grab the center setion of the "live" picture box and display it in the "photo" picture box. (This gives the impression that there are two video feeds - but we cheeted!).  When they capture the image they actually capture the "photo" picture box and not the live feed getting nicely round the camera support. 

     

    All this worked brilliantly.  Then they went and bought Sony Vaio laptops with built in cameras,

     

    What fappens now is that the software randomly picks one of the cameras.  Sometimes its the built in one, and sometimes its the Lifecam.  We need it always to be the life cam.

     

    So what I need to be able to do is to allow the user to pick which camera to use.  All the cpturing is working fine.

     

    Thanks

     

    Steve

    Wednesday, May 30, 2007 8:46 AM
  •  

    Have ever read this article below?

     

    Teach Your Old Web Cam New Tricks: Use Video Captures in Your .NET Applications

    http://www.devx.com/dotnet/Article/30375?type=kbArticle&trk=MSCP

     

    I hope the article can give you more helps. :-)

    Wednesday, May 30, 2007 9:05 AM
  • Hi Bruno,

     

    Thanks again.

     

    That code was very similar to wjat I had, apart from the bit that lists available drivers.  I have added that bit but have come accross another slight problem.

     

    The only driver listed is "Microsoft WDM Image Capture (Win32)"

     

    Both cameras are availbel through the control panel and through Windows Explorer.

     

    Now I am puzzled

     

    Thanks

     

    Steve

    Wednesday, May 30, 2007 12:40 PM
  • Hi  Steve

     

    Thank god i found you! Having the same problem i have. Did you get any idea how to do it yet? I have searched through the internet and can't find the solution yet.  What a pitty!

     

    Anyway, I hope you can find the solution soon. If I do, i will let you know...

     

     

    Piya

    Thursday, June 14, 2007 4:18 AM
  • You can send a windows message to the video device handler that will activate a Video Source dialog that typically allows you to select which of the multiple cameras being serviced by the handler to use.  The message ID is: WM_CAP_DLG_VIDEOSOURCE.  The problem with this approach is that it requires user interaction, for example, you can't program the application to always select the second webcam.  If you don't mind a user dialog solution, the WM_CAP_DLG_VIDEOSOURCE approach should work fine.

     

    Let me know if you want sample code.

     

    Randy

     

    Tuesday, October 23, 2007 3:46 PM
  •  

    Thanx for a valueable sharing of yoru experiences.

     

    i had a same problem that, i dont want user interaction for selecting Video Source Dialog. i want to handl it programatically, but how this is the actual question. I will appreciate Randy if you could pleas share sample code to avoid user interaction "Video Source Dialog" for selecting two webcams.

     

    desperatelly waiting your reply

     

    Hannan

    Thursday, February 21, 2008 4:05 AM
  •  

    Hi guys,

    i recently bought 7 cheap web cams ambitiously thinking i could easily write an application to monitor all 7 symultaneously. oh i love learning things the hard way.

     

    Anyway, The application ive written so far cant monitor all 7 at once, but it can switch cameras automatically without user interaction. it uses the avicap32.dll. I dont know if it will be any use to anyone but heres how i did it.

     

    I discovered that when the user chose the camera source from the dialog that appears, it would write the path to the device in the registry, in the key HKLM\System\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM to a string called DevicePath.

     

    So when the user launches the program for the first time, the program asks the user if they want to add a camera and goes into a loop until the answer is no.

     

    in the loop:

    the string DevicePath is deleted from the above mentioned key

    the program then tells the driver to "connect", since avicap doesnt know which device to connect to it throws a dialog to the user asking which device to connect to.

    when the user choses the device, the driver connects and displays a preview

    the program then looks at the DevicePath string in the above mentioned key and saves the value to the program settings

    my.settings.cameras.add(

    My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM", "DevicePath", Nothing))

     

    when the user clicks No, they dont want to add any more cameras the program should now have an array of device paths for each camera attached.

     

    now when the user clicks the button to start to capture, the program iterates through the array, chosing the next device in the array, it sets the value of DevicePath to the value of the selected element in the array, it tells the driver to connect and send the output to a picturebox for preview, then tells the driver to take a snapshop, saves the snapshot to disk, tells the driver to disconnect, and then deletes the value of DevicePath and the loop starts again.

     

    this works, but isnt ideal. Ive found that each cycle for each camera takes about 2.5 to 3 seconds for the driver to connect, take snapshot, then disconnect. this means that if ive got 7 cameras attached it takes the program about 20 seconds to take snapshots from all 7 cameras.

     

    anyway, it works for now. im actually trying to achieve a capture rate of at least 4 shots per second per camera, symultaneously.

     

    ive got no idea if its possible using avicap32.dll but heres my theory (in case you were interested).

    when then program tells the driver to connect, it reads the device path from the above mentioned registry key. the driver should only need to do this when it connects.

     

    so I figure i can iterate through the device array, set the devicepath value in the registry, tell the driver to connect and send output to a new instance of the picturebox, then iterate to the next device, set the device path value in the registry, and tell the driver to connect and send output to a new instance of picturebox.

     

    that way we get all cameras connected at the start of the program and dont have to worry about disconnecting the camera, switching the camera, reconnecting, etc..

     

    no idea if this will work, im going to give it a try.

    Friday, March 14, 2008 1:24 PM
  • Hi Often Drunk,


    what you try to do with different cameras using avicap32 is very interresting...
    I've tried to implement it following the information you gave, but even when I modify the DevicePath value in the registry before connecting the vfw driver, the Video Source Selection windows keeps on poping-up...

    Can you give more information on how you performed the camera source swithing, or even provide a code snippet... that would be great

    Thanks in advance

    Bruno.
    Friday, May 30, 2008 3:42 PM
  • Often Drunk's post was very helpful to me.

    In a nut shell, changing the DevicePath key does infact change the source of the current video device.  But know that you have to manually stop and start the capture from code.  After searching the registry for the value of the DevicePath I was able to find out not only the location of ALL of the video capture devices, but the names and whether or not they are currently connected (AKA Linked) to the PC!

    Using the below code in conjuction with Drunk's post you will be able to have a complete list of the capture devices as well as the ability to select them.

    For anyone else that needs the following code to help them locate all of the video devices (including webcams) installed on a particular machine... here it is:

    ' Note: This is in Visual Basic 6 (But you should be able to convert to .NET)  
    ' Note: place the following code in a Module  
     
    ' Structure (UDT) for the available device information  
    Public Type WebCamDevice  
        FriendlyName As String 
        SymbolicLink As String 
        Linked As Boolean 
        Selected As Boolean 
    End Type  
     
    Public Function EnumVideoDevices(ByRef WebCamDevices() As WebCamDevice)  
        Dim CurrentDevice As String 
        Dim DeviceClassId As String 
        Dim Index As Long 
        Dim DeviceKey As String 
          
        Dim hKey As Long 
        Dim SubKey As String 
        Dim sName As String 
        Dim Cnt As Long 
        Dim Ret As Long 
        Dim KeyName As String 
        Dim NewSubKey As String 
          
        'Dim WebCamDevices() As WebCamDevice  
        Dim Ubnd As Long 
        Dim WebCamDevice As WebCamDevice  
        Dim WebCamDeviceNul As WebCamDevice  
        Dim WaveKeyFound As Boolean 
        Dim ControlKeyFound As Boolean 
        Dim OkToAdd As Boolean 
          
        CurrentDevice = GetString(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM""DevicePath")  
          
        ' If there is no Device selected, then loop through the MediaCategories key to find Capture  
        If LenB(CurrentDevice) = 0 Then 
          
            ' Get the DeviceClassId  
            DeviceClassId = vbNullString  
            'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MediaCategories\{65E8773D-8F56-11D0-A3B9-00A0C9223196}  
            SubKey = "SYSTEM\CurrentControlSet\Control\MediaCategories" 
            If RegOpenKey(HKEY_LOCAL_MACHINE, SubKey, hKey) = 0 Then 
                'Create a buffer  
                sName = Space(BUFFER_SIZE)  
                Ret = BUFFER_SIZE  
                  
                Cnt = 0  
                'Enumerate the keys  
                Do While (RegEnumKeyEx(hKey, Cnt, sName, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS)  
                    'Show the enumerated key  
                    KeyName = Left$(sName, Ret)  
                      
                    If GetString(HKEY_LOCAL_MACHINE, SubKey & "\" & KeyName, "Name") = "Capture" Then 
                        DeviceClassId = KeyName  
                        Exit Do 
                    End If 
                      
                    'prepare for the next key  
                    Cnt = Cnt + 1  
                    sName = Space(BUFFER_SIZE)  
                    Ret = BUFFER_SIZE  
                Loop 
                'close the registry key  
                RegCloseKey hKey  
            End If 
          
        Else 
              
            ' Get the id from the last item used  
            Index = InStr(CurrentDevice, "{")  
            DeviceClassId = Mid$(CurrentDevice, Index, 38)  
              
        End If 
          
        If LenB(DeviceClassId) = 0 Then 
            ' Ask the user - We have no idea where this is located in the registry  
            Exit Function 
        End If 
          
        Erase WebCamDevices  
        Ubnd = -1  
        'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{65E8773D-8F56-11D0-A3B9-00A0C9223196}  
        DeviceKey = "SYSTEM\CurrentControlSet\Control\DeviceClasses\" & DeviceClassId  
        If RegOpenKey(HKEY_LOCAL_MACHINE, DeviceKey, hKey) = 0 Then 
            'Create a buffer  
            sName = Space(BUFFER_SIZE)  
            Ret = BUFFER_SIZE  
            Cnt = 0  
              
            'Enumerate the keys  
            Do While (RegEnumKeyEx(hKey, Cnt, sName, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS)  
                'Show the enumerated key  
                KeyName = Left$(sName, Ret)  
                  
                'WebCamDevice  
                  
                If LenB(KeyName) <> 0 Then 
                    NewSubKey = DeviceKey & "\" & KeyName  
                      
                    WebCamDevice = WebCamDeviceNul  
                    OkToAdd = False 
                    WaveKeyFound = False 
                    ControlKeyFound = False 
                      
                    Call PopulateWebCamDevice(NewSubKey, WebCamDevice, WaveKeyFound, ControlKeyFound)  
                      
                    If WaveKeyFound = False And ControlKeyFound = True And LenB(WebCamDevice.SymbolicLink) <> 0 Then 
                        OkToAdd = True 
                    End If 
                      
                    If OkToAdd = True Then 
                        ' Determine if this device is the one with is currently selected  
                        If UCase$(CurrentDevice) = UCase$(WebCamDevice.SymbolicLink) Then 
                            WebCamDevice.Selected = True 
                        End If 
                      
                        Ubnd = Ubnd + 1  
                        ReDim Preserve WebCamDevices(Ubnd)  
                        WebCamDevices(Ubnd) = WebCamDevice  
                    End If 
                End If 
                  
                'prepare for the next key  
                Cnt = Cnt + 1  
                sName = Space(BUFFER_SIZE)  
                Ret = BUFFER_SIZE  
            Loop 
            'close the registry key  
            RegCloseKey hKey  
        End If 
     
     
    End Function 
     
    Private Sub PopulateWebCamDevice(ByVal SubKey As StringByRef WebCamDevice As WebCamDevice, ByRef WaveKeyFound As BooleanByRef ControlKeyFound As Boolean)  
        Dim hKey As Long 
        Dim sName As String 
        Dim Cnt As Long 
        Dim Ret As Long 
        Dim KeyName As String 
        Dim NewSubKey As String 
          
        Dim SymbolicLink As String 
        Dim FriendlyName As String 
        Dim Linked As Long 
          
        If RegOpenKey(HKEY_LOCAL_MACHINE, SubKey, hKey) = 0 Then 
            'Create a buffer  
            sName = Space(BUFFER_SIZE)  
            Ret = BUFFER_SIZE  
            Cnt = 0  
              
            'Enumerate the keys  
            Do While (RegEnumKeyEx(hKey, Cnt, sName, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS)  
                'Show the enumerated key  
                KeyName = Left$(sName, Ret)  
                  
                If LenB(KeyName) <> 0 Then 
                      
                    Select Case UCase$(KeyName)  
                        Case "#WAVE" 
                            WaveKeyFound = True 
                        Case "CONTROL" 
                            ControlKeyFound = True 
                    End Select 
                      
                    NewSubKey = SubKey & "\" & KeyName  
                      
                    SymbolicLink = GetString(HKEY_LOCAL_MACHINE, NewSubKey, "SymbolicLink")  
                    If LenB(SymbolicLink) <> 0 Then 
                        WebCamDevice.SymbolicLink = SymbolicLink  
                    End If 
                      
                    FriendlyName = GetString(HKEY_LOCAL_MACHINE, NewSubKey, "FriendlyName")  
                    If LenB(FriendlyName) <> 0 Then 
                        WebCamDevice.FriendlyName = FriendlyName  
                    End If 
                      
                    Linked = GetLong(HKEY_LOCAL_MACHINE, NewSubKey, "Linked")  
                    If Linked <> 0 Then 
                        WebCamDevice.Linked = True 
                    End If 
                      
                    Call PopulateWebCamDevice(NewSubKey, WebCamDevice, WaveKeyFound, ControlKeyFound)  
                End If 
                  
                'prepare for the next key  
                Cnt = Cnt + 1  
                sName = Space(BUFFER_SIZE)  
                Ret = BUFFER_SIZE  
            Loop 
            'close the registry key  
            RegCloseKey hKey  
        End If 
     
    End Sub 
     
    Public Function SafeUbound(ByRef Ary As VariantAs Long 
        SafeUbound = -1  
        On Error Resume Next 
        SafeUbound = UBound(Ary)  
        On Error GoTo 0  
    End Function 
     
    Sunday, June 15, 2008 1:24 PM
  • You both Often Drunk and vbguyny geniuses , I just kneel down before you and applaud ... :-)
    Thursday, February 04, 2010 12:57 PM
  • Hello,

    Kishorfarm, did you succed using the proposal of Often Drunk and vbguyny.

    Do you agree to share source code on this subject because I have difficulties to make it run.

     

    Thanks for your answer.

    Monday, May 10, 2010 10:58 AM
  • Sir, can you make some sample of this program? If it is ok to you. It will be highly appreciated. thank you very much.
    Saturday, July 17, 2010 5:45 PM
  • Mr vbguyny,

    I'm trying to use your code but not working. In my project I need to view two webcams at the same time, then take a picture of each of the images.

    Please Help me.

    asdrubal_ramirez@hotmail.com

    Wednesday, April 27, 2011 7:50 PM
  • I have successfully leveraged off the work from vbguyny and Christopher MCSE  to kick two cameras without the popup dialog box.

    Thank you to both of you for the tips.

    The code provided above has references to functions like Getstring that wasnt included, but after I simplied the code it is a matter of

    1. RegOpenKey HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM", lngKey
    2. RegSetValueEx lngKey, "DevicePath", 0, 1, ByVal Strdata, Len(Strdata)
    3. RegCloseKey lngKey
    4. capCreateCaptureWindow("CaptureWindow", WS_CHILD Or WS_VISIBLE, 0, 0, 0, 0, Picture4.hwnd, 0)

    Then repeat 1-4 but this time write the second devicepath to registry and then kick the second camera.

    PS. Remember not to put "SendMessage hCapWin2, WM_CAP_DLG_VIDEOSOURCE, 0, 0" so the video source window wont pop up.



    • Edited by Ricky Luk Sunday, December 04, 2011 12:48 PM
    Sunday, December 04, 2011 12:47 PM
  • Hello Ricky Luk,

     

    Do you have complete code to preview 2 webcams?.

     

    Thanks in advance.

     

    Tuesday, January 03, 2012 5:57 AM
  • Option Explicit
    ' *******************************************************************************
    ' ModCamReg.Bas : WebCam Regitry routine. Enumerate all attach webcam with Linked
    ' Coded by      : tmax_visiber@yahoo.com
    ' Ref           : http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/c4fd12d8-2870-47ed-8f2e-3dc613afeb6f/
    ' *******************************************************************************
    
    Public Type VideoDevice
        FriendlyName As String
        SymbolicLink As String
        Linked As Boolean
        Selected As Boolean
    End Type
    
    Function GetCurrentWebCam() As String
      Dim WSHShell As Object
      Dim MyRegKey As String
      Set WSHShell = CreateObject("WScript.Shell")
      MyRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM\DevicePath"
      GetCurrentWebCam = WSHShell.regread(MyRegKey)
      Set WSHShell = Nothing
    End Function
    
    Sub SetCurrentWebCam(Camstr As String)
      Dim WSHShell As Object
      Dim MyRegKey As String
      Set WSHShell = CreateObject("WScript.Shell")
      MyRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM\DevicePath"
      WSHShell.regwrite MyRegKey, Camstr
      Set WSHShell = Nothing
    End Sub
    
    ' Code idea from vbguyny, modified by Tmax
    Sub EnumVideoDevices(wcam() As VideoDevice)
      Const HKLM = &H80000002
      Dim i As Long
      Dim j As Long
      Dim k As Long
      Dim objReg
      Dim arrOut1, arrOut2, arrOut3
      Dim intRet
      
      Dim Linked As Long
      Dim FriendlyName As String
      Dim SymbolicLink As String
      
      Dim LinkedKey As String
      Dim SymbolicLinkKey As String
      Dim FriendlyNameKey As String
      
      Dim Cnt As Integer
      Dim EnumRet1, EnumRet2, EnumRet3
      
      Dim DeviceList() As String
      Dim DeviceClassId As String
      Dim DeviceClassIDChild As String
      Dim CurrentDevice As String
      Dim GetDeviceClassId As String
      
      Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
      intRet = objReg.GetStringValue(HKLM, "SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM", "DevicePath", CurrentDevice)
      i = InStr(CurrentDevice, "{")
      GetDeviceClassId = Mid$(CurrentDevice, i, 38)
      DeviceClassId = "SYSTEM\CurrentControlSet\Control\DeviceClasses\" & GetDeviceClassId
        EnumRet1 = objReg.EnumKey(HKLM, DeviceClassId, arrOut1)
        If EnumRet1 = 0 Then
          ReDim DeviceList(UBound(arrOut1))
          For i = 0 To UBound(arrOut1)
            DeviceClassIDChild = DeviceClassId & "\" & arrOut1(i)
            DeviceList(i) = DeviceClassIDChild
          Next i
        Else
          Debug.Print "key is not here"
        End If
        
        For i = 0 To UBound(DeviceList)
          If Right(DeviceList(i), 1) <> "\" Then
            EnumRet2 = objReg.EnumKey(HKLM, DeviceList(i), arrOut2)
              If EnumRet2 = 0 Then
                For j = 0 To UBound(arrOut2)
                  If Mid$(arrOut2(j), 1, 1) = "#" Then
                    EnumRet3 = objReg.EnumKey(HKLM, DeviceList(i) & "\" & arrOut2(j), arrOut3)
                    If EnumRet3 = 0 Then
                      For k = 0 To UBound(arrOut3)
                          If UCase$(arrOut3(k)) = "CONTROL" Then
                            SymbolicLinkKey = DeviceList(i) & "\" & arrOut2(j)
                            LinkedKey = DeviceList(i) & "\" & arrOut2(j) & "\Control"
                            FriendlyNameKey = DeviceList(i) & "\" & arrOut2(j) & "\Device Parameters"
                            intRet = objReg.GetDWORDValue(HKLM, LinkedKey, "Linked", Linked)
                            intRet = objReg.GetStringValue(HKLM, FriendlyNameKey, "FriendlyName", FriendlyName)
                            intRet = objReg.GetStringValue(HKLM, SymbolicLinkKey, "SymbolicLink", SymbolicLink)
                             ' Bypass any SymbolicLink contains "WAVE" and FriendName contains "MIC" or "MIDI"
                            If Linked = 1 And InStr(UCase$(FriendlyName), "MIC") = 0 And InStr(UCase$(FriendlyName), "MIDI") = 0 And InStr(UCase$(SymbolicLink), "WAVE") = 0 Then
                              ReDim Preserve wcam(Cnt)
                              With wcam(Cnt)
                                .Linked = True
                                .FriendlyName = FriendlyName
                                .SymbolicLink = SymbolicLink
                                ' Current selected Device
                                If UCase$(CurrentDevice) = UCase$(.SymbolicLink) Then
                                  .Selected = True
                                End If
                              End With
                              Cnt = Cnt + 1
                            End If
                          End If
                      Next k
                  End If
                End If
              Next j
            End If
          End If
        Next i
    End Sub
    
    'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{65E8773D-8F56-11D0-A3B9-00A0C9223196}\##?#USB#VID_046D&PID_09A4&MI_00#8&2C27D0E0&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\#{BBEFB6C7-2FC4-4139-BB8B-A58BBA724083}\Control]
    ''''"Linked"=dword:00000001
    
    Function CheckInitReg() As Boolean
      Dim WSHShell As Object
      Dim MyRegKey As String
      Dim RegStr As String
      Set WSHShell = CreateObject("WScript.Shell")
      MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\"
      On Error GoTo RegErr
      RegStr = WSHShell.regread(MyRegKey)
      If Len(RegStr) > 0 Then CheckInitReg = True
      Set WSHShell = Nothing
      Exit Function
    RegErr:
      CheckInitReg = False
      Set WSHShell = Nothing
    End Function
    
    Sub CamInit()
      Dim WSHShell As Object
      Dim MyRegKey As String
      Dim i As Integer
      Dim Vd() As VideoDevice
      EnumVideoDevices Vd()
      Set WSHShell = CreateObject("WScript.Shell")
      MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\"
      WSHShell.regwrite MyRegKey, Format$(Now, "yyyy-mm-dd hh:mm:ss")
      MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Vendor"
      WSHShell.regwrite MyRegKey, App.CompanyName
      MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Version"
      WSHShell.regwrite MyRegKey, App.Major & "." & App.Minor & "." & App.Revision
      MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Count"
      WSHShell.regwrite MyRegKey, UBound(Vd())
      For i% = 0 To UBound(Vd())
        MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Cam" & Format$(i%, "0#") & "\FriendlyName"
        WSHShell.regwrite MyRegKey, Vd(i%).FriendlyName
        MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Cam" & Format$(i%, "0#") & "\SymbolicLink"
        WSHShell.regwrite MyRegKey, LCase$(Vd(i%).SymbolicLink)
      Next i%
      Set WSHShell = Nothing
    End Sub
    
    Sub GetCamFromReg(cboCamSource As ComboBox, CamSymbolicLink() As String)
      Dim WSHShell As Object
      Dim MyRegKey As String
      Dim RegStr As String
      Dim i As Integer
      Set WSHShell = CreateObject("WScript.Shell")
      MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Count"
      RegStr = WSHShell.regread(MyRegKey)
      ReDim CamSymbolicLink(Val(RegStr))
      For i% = 0 To Val(RegStr)
        MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Cam" & Format$(i%, "0#") & "\FriendlyName"
        RegStr = WSHShell.regread(MyRegKey)
        cboCamSource.AddItem RegStr
        MyRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MultiCam\Cam" & Format$(i%, "0#") & "\SymbolicLink"
        RegStr = WSHShell.regread(MyRegKey)
        CamSymbolicLink(i%) = RegStr
      Next i%
      Set WSHShell = Nothing
    End Sub
    
    
    

    'Form1
    
    Option Explicit
    Dim CamSymbolicLink() As String
    
    Private Sub cboCamSource_Click()
    Text1 = CamSymbolicLink(Val(cboCamSource.ListIndex))
    ''SetCamSource
    End Sub
    
    Private Sub Form_Load()
      If Not CheckInitReg Then
        Me.Caption = "Enumerates Video Source ..."
        CamInit
      End If
      GetCamFromReg cboCamSource, CamSymbolicLink()
      cboCamSource.ListIndex = 0
      'ResizePreviewWindow
    End Sub
    
    Sub SetCamSource()
      If CamSymbolicLink(Val(m_CamSource)) <> GetCurrentWebCam Then
        SetCurrentWebCam CamSymbolicLink(Val(cboCamSource.ListIndex))
      End If
     ' ResizePreviewWindow
    End Sub
    Hope this will solve the problem ~
    Tuesday, March 27, 2012 3:46 PM
  • For those like me who assumed VBGuyNy's code snippet was a complete example (and pasted it into a template application), it's not...  (Ref VBGuyNy's midway above, Sunday, June 15, 2008 1:24 PM [or just above depending where you are reading this comment]). Please see the excellent TMax97 complete tested/working example below (March 27, 2012 3:46 PM [or just above depending where you are reading this comment]). (Thanks VBGuyNy, I do appreciate the trouble you went to, but always helps if you advise if not complete).
    • Edited by Continuity police Tuesday, November 12, 2013 12:53 PM As MS seem to publish replies all over the place, i made it more obvious which actual entries I'm replying to!
    Tuesday, November 12, 2013 12:17 PM
  • Thank you Tmax97 for your tested working example -- that was brilliant!
    Tuesday, November 12, 2013 12:36 PM