How to get list of connected WebCams in avicap32.dll?

10,152

Solution 1

This is legacy API (Video for Windows, avicap32.dll) and it is not that flexible as you could expect. Still being supported though.

Newer API with the best coverage is DirectShow, it is native, but with DirectShow.NET you have a bridge into .NET. Take a look at code sample and article inroducing this approach: Finding Your Web Cam with C# & DirectShow.NET

Edit: Original article no longer exists, however found a copy in the Internet Archive https://archive.org/web/

Solution 2

Its easier and better to use the AForge.NET library. It contains all the tools to do these kind of jobs http://aforgenet.com/

Share:
10,152
Sushi271
Author by

Sushi271

Updated on June 05, 2022

Comments

  • Sushi271
    Sushi271 almost 2 years

    I'm coding an application to handle WebCams. I have to use (this is an external constraint) the avicap32.dll library. So here I am, using some extern functions (for which I have to marshal types) from this library, as well as user32 (sending WindowsMessages). And I digged up half the Internet, but failed to find how to get list of all the connected WebCam devices?

    Of course I'm fully aware of function:

    [DllImport(avicap32dll)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool capGetDriverDescription(
        short driverIndex,
        StringBuilder name, int nameSize,
        StringBuilder version, int versionSize);
    

    , but it gives me list of drivers, not cams! When I connect two cameras to my PC, I still can find only one capture driver by this function (checking driverIndex from 0 to 9). Both of them must be using the same capture driver. So, not having a list of WebCams I cannot really decide, to which one I want to connect. There is a WindowsMessage WM_CAP_DLG_VIDEOSOURCE, but it doesn't show video source dialog before I connect with a WebCam.

  • Jonathan
    Jonathan about 11 years
    Thank you. It helped me as well, I've been using avicap32.dll and it never really did what I wanted.