How to get a list of connected capture devices?

Hello,

I am trying to capture some images via a USB connected digital camera…

I am using this code…

  Declare Function SendMessage lib "user32" alias "SendMessageA"(hwnd as integer,wMsg as integer,wParam as integer,lParam as integer)AS integer
  Const WM_CAP_SET_PREVIEW = 1074
  Const WM_CAP_SET_PREVIEWRATE = 1076
  Const WM_CAP_SET_SCALE = 1077
  Const WM_CAP_DRIVER_DISCONNECT = 1035
  Const WM_CAP_DRIVER_CONNECT = 1034
  Const WS_VISIBLE = &h10000000
  Const WS_CHILD = &h40000000
  Const WM_CAP_DLG_VIDEOSOURCE = 42
  
  If cap <> 0 Then Call SendMessage(cap,WM_CAP_DRIVER_DISCONNECT,0,0)

It works via the built-in video camera.

How can I modify that to get a list of connected capture devices?

Actually, I would like to get it working with the USB connected digital camera when it is connected.

Thanks.

Lennox

To get a list of devices use the capGetDriverDescriptionW function:

  Declare Function capGetDriverDescriptionW Lib "Avicap32" (DriverIndex As UInt16, DriverName As Ptr, _
      NameLen As Integer, DriverVersion As Ptr, VersionLen As Integer) As Boolean
  Dim count As Integer
  Dim names() As String
  Dim nm As New MemoryBlock(1024)
  
  While capGetDriverDescriptionW(count, nm, nm.Size, Nil, 0)
    count = count + 1
    names.Append(nm.WString(0))
  Wend

See also this previous discussion.

Thanks Andrew,

“To get a list of devices use the capGetDriverDescriptionW function:” works but only the built-in camera is displayed…
Microsoft WDM image Capture (Win32)

The other capture device is not listed
The camera, Nikon D3200, http://imaging.nikon.com/lineup/dslr/d3200/, is connected via Video2PC, https://noterepeat.com/products/ion/vcrs-and-video-conversion/383-ion-audio-video-2-pc-mkii-driver-installation-and-software-setup, through a USB port.

I had to modify it like this though…

  Declare Function capGetDriverDescriptionW Lib "Avicap32" (DriverIndex As UInt16, DriverName As Ptr, _
  NameLen As Integer, DriverVersion As Ptr, VersionLen As Integer) As Boolean
  Dim count As Integer
  Dim names() As String
  Dim DeviceNames As String
  Dim nm As New MemoryBlock(1024)
  
  While capGetDriverDescriptionW(count, nm, nm.Size, Nil, 0)
    count = count + 1
    DeviceNames = DeviceNames + chr(13) + nm.WString(0)
  Wend
  
  msgbox DeviceNames

If I use the camera with Video2PC I have to use a program that came with it, PowerDirector 9, I can capture images with the Nikon D3200.

Any suggestion why the other capture device is not listed?

I tried your suggestion from https://forum.xojo.com/32493-help-with-c-to-xojo-conversion-solved/

Try creating a new blank project and copy this into the Window1.Open event:

Declare Function capGetDriverDescriptionW Lib "Avicap32" (DriverIndex As UInt16, DriverName As Ptr, NameLen As Integer, DriverVersion As Ptr, VersionLen As Integer) As Boolean
  Dim i As Integer
  Dim nm As New MemoryBlock(1024)
  Do Until Not capGetDriverDescriptionW(i, nm, nm.Size, Nil, 0)
    MsgBox(nm.WString(0))
    i = i + 1
    nm = New MemoryBlock(1024)
  Loop

It should pop-up a msgbox for each available camera interface. I’m kind of skeptical but it’s the only thing I can think of.

Only the built in camera pops up… Microsoft WDM image Capture (Win32)

Thanks.

I’m afraid I don’t know why your camera doesn’t show up in the list. I’ve only got two cameras to test with and it works fine for me for both.

Does it show as a webcam, camera or something else under Devices and Printers in Control Panel?

Where does it show up under Device Manager?

Does it show up in other video capture software?

What I’m getting at, is that it might not emulate a “real” webcam or video source and might be specifically written to work with PowerDirector. Long shot, but it might be the case.

Thanks Andrew.

Julian, I do not have it now but tomorrow I will check and see.

I only tried it with PowerDirector, any other software that comes to mind that I can try?

Thanks again.

Lennox

I use https://www.techsmith.com/camtasia.html for desktop recording, it also has a webcam button at the bottom when you go to make a recording. They offer a free trial so that should be suitable for your test. Good luck :slight_smile:

Hi Andrew and Julian,

Thanks for your input, time and interest,

My camera is not a dedicated WebCam it has to use Video2PC or some other kind of hardware to do that.

Apparently this cannot be done in VB or VB modified code.

DirectShow seem to be able to do it… https://www.codeproject.com/kb/audio-video/webcamusingdirectshownet.aspx

I do not know how to use VBstudio and I don’e have VBstudio, so I have given up.

Thanks again.

Lennox

MBS has a direct show plugin for Xojo here https://www.monkeybreadsoftware.de/xojo/plugin-directshow.shtml with a free trial. Worth a try.

Thanks Julian,

I have never used plugins before, I downloaded it, will try it.

Thanks again

Lennox