Page 1 of 1

Obtener un array con las webcams instaladas

PostPosted: Sun Dec 05, 2010 11:27 pm
by jll-fwh
Hola a todos:

Alquien podria decirme como puedo obtener un array con los dispositivos instalados para webcam?

Estoy utilizando la clase TCapCapture de Rafa ( TheFull ), pero no logro saber como obtener cuantas webcam tengo instaladas, estoy probando con 3.

Otra cuestion:

Esta clase con equipos portatiles nuevos no funciona, pero en cambio si abres el Messenguer, funciona OK, alguien se le ocurre porque con esta clase no activa el controlador en portatiles y cuando el MSN esta abierto funciona porque abre el controlador el MSN?

Muchas gracias de antemano
un saludo
JLL

Re: Obtener un array con las webcams instaladas

PostPosted: Tue Dec 07, 2010 12:35 am
by Daniel Garcia-Gil
Saludos

Te dejo un codigo, que por necesidad tuve que elaborarlo en CPP, al parecer funciona bien

Descarga Ejemplo AQUI

PRG

Code: Select all  Expand view

#include "fivewin.ch"

function main()
   
   xbrowse( EnumDevice() )
   
return nil


CPP
Code: Select all  Expand view

#include <windows.h>
#include <hbapi.h>
#include <objidl.h>
#include <strmif.h>
#include <uuids.h>
#include <vfwmsgs.h>
#include <hbapiitm.h>

HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum)
{
    // Create the System Device Enumerator.
   
    ICreateDevEnum *pDevEnum;
    HRESULT hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, ( void **)&pDevEnum );

    if (SUCCEEDED(hr))
    {
        // Create an enumerator for the category.
        hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0);
        if (hr == S_FALSE)
        {
            hr = VFW_E_NOT_FOUND;  // The category is empty. Treat as an error.
        }
        pDevEnum->Release();
    }
    return hr;
}

void DisplayDeviceInformation(IEnumMoniker *pEnum, PHB_ITEM * pArray)
{
    IMoniker *pMoniker = NULL;
    PHB_ITEM pDevices = hb_itemArrayNew( 0 );
   
    while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
    {
        IPropertyBag *pPropBag;
        HRESULT hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag );
        if (FAILED(hr))
        {
            pMoniker->Release();
            continue;  
        }

        VARIANT var;
        VariantInit(&var);

        // Get description or friendly name.
        hr = pPropBag->Read(L"Description", &var, 0);
        if (FAILED(hr))
        {
            hr = pPropBag->Read(L"FriendlyName", &var, 0);
        }
        if (SUCCEEDED(hr))
        {
              PHB_ITEM pItem = hb_itemNew( NULL );
              wchar_t * bstrVal = var.bstrVal;
              char * strVal = hb_wctomb( bstrVal );
              hb_itemPutC( pItem, strVal );
              hb_arrayAddForward( pDevices, pItem );
              hb_itemRelease( pItem );
            VariantClear(&var);
            hb_xfree( strVal );
        }
        *pArray = pDevices;
        pPropBag->Release();
        pMoniker->Release();
    }
}

HB_FUNC( ENUMDEVICE )
{
    HRESULT hr = CoInitialize(NULL);
    PHB_ITEM pArrayDevice;
   
    if (SUCCEEDED(hr))
    {
        IEnumMoniker *pEnum;

        hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
        if (SUCCEEDED(hr))
        {
            DisplayDeviceInformation( pEnum, &pArrayDevice);
            pEnum->Release();
        }

        CoUninitialize();
    }
    hb_itemReturnRelease( pArrayDevice );
   
}
 

Re: Obtener un array con las webcams instaladas

PostPosted: Tue Dec 07, 2010 1:30 am
by jll-fwh
Hola Daniel

Como siempre muchas gracias por ayudarme.

He insertado en la clase la parte de codigo que me has pasado para capturas las webcams que tengo instaladas pero me da error. Yo aqui yo ya me pierdo.


C:\JLLORISH\Pruebas\fotocam>c:\bcc55\bin\make -ftest.rmk
MAKE Version 5.2 Copyright (c) 1987, 2000 Borland
c:\harbour\bin\harbour .\ALERT.PRG /L /N /W /P /Oobj\ /Ic:\fwh\include;c:\harbour\include
c:\bcc55\bin\bcc32 -c -tWM -Ic:\harbour\include -oobj\ALERT obj\ALERT.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
obj\ALERT.c:
Error E2342 .\\ALERT.PRG 614: Type mismatch in parameter 'rclsid' (wanted 'const _GUID * const', got '_GUID') in function EnumerateDevices
Error E2342 .\\ALERT.PRG 614: Type mismatch in parameter 'riid' (wanted 'const _GUID * const', got '_GUID') in function EnumerateDevices
Error E2451 .\\ALERT.PRG 619: Undefined symbol 'CreateClassEnumerator' in function EnumerateDevices
Error E2451 .\\ALERT.PRG 624: Undefined symbol 'Release' in function EnumerateDevices
Warning W8057 .\\ALERT.PRG 627: Parameter 'category' is never used in function EnumerateDevices
Warning W8057 .\\ALERT.PRG 627: Parameter 'ppEnum' is never used in function EnumerateDevices
Error E2451 .\\ALERT.PRG 634: Undefined symbol 'Next' in function DisplayDeviceInformation
Error E2451 .\\ALERT.PRG 637: Undefined symbol 'BindToStorage' in function DisplayDeviceInformation
Error E2451 .\\ALERT.PRG 640: Undefined symbol 'Release' in function DisplayDeviceInformation
Error E2140 .\\ALERT.PRG 644: Declaration is not allowed here in function DisplayDeviceInformation
Error E2451 .\\ALERT.PRG 648: Undefined symbol 'Read' in function DisplayDeviceInformation
Error E2451 .\\ALERT.PRG 651: Undefined symbol 'Read' in function DisplayDeviceInformation
Error E2451 .\\ALERT.PRG 656: Undefined symbol 'bstrVal' in function DisplayDeviceInformation
Error E2451 .\\ALERT.PRG 665: Undefined symbol 'Release' in function DisplayDeviceInformation
Error E2451 .\\ALERT.PRG 666: Undefined symbol 'Release' in function DisplayDeviceInformation
Warning W8004 .\\ALERT.PRG 668: 'pMoniker' is assigned a value that is never used in function DisplayDeviceInformation
Warning W8057 .\\ALERT.PRG 668: Parameter 'pEnum' is never used in function DisplayDeviceInformation
Error E2342 .\\ALERT.PRG 679: Type mismatch in parameter 'category' (wanted 'const _GUID * const', got '_GUID') in function HB_FUN_ENUMDEVICE
Error E2451 .\\ALERT.PRG 683: Undefined symbol 'Release' in function HB_FUN_ENUMDEVICE
*** 15 errors in Compile ***

** error 1 ** deleting .\obj\ALERT.OBJ


Un saludo
JLL

Re: Obtener un array con las webcams instaladas

PostPosted: Tue Dec 07, 2010 1:53 am
by Daniel Garcia-Gil
Saludos

No puedes incluir el código dento del PRG debes compilarlo como CPP
Intenta compilar el ejemplo que publique, dentro esta un .bat para construir

Re: Obtener un array con las webcams instaladas

PostPosted: Tue Dec 07, 2010 2:43 am
by jll-fwh
Ok daniel:

Ya te comento.

Luego quiero comentarte tambien una cosa que funciona pero hay un pequeño detalle a ver si tu sabes.

P.D Te agrege al msn, pero creo que no me has aceptado porque no sabrias quien era, te importa agregarme al msn?

Cuenta MSN: fwh-jll@hotmail.es

Un saludo
JLL

Re: Obtener un array con las webcams instaladas

PostPosted: Tue Dec 07, 2010 6:04 am
by Daniel Garcia-Gil
Jll

aqui te dejo el obj para la version que usas, lo puedes usar para la version de borland que usas

http://www.sitasoft.com/fivewin/files/enumpp.obj