yushulx / python-capture-device-list

MIT License
95 stars 34 forks source link

return null without setting an error #1

Open Starxyz opened 5 years ago

Starxyz commented 5 years ago

image hello~ I got this error when i use window 7 x64 , but everything is OK in win10. How can I fix it?

Barmaley13 commented 5 years ago

That needs to be fixed in C but you can wrap your code into try - except guards for now in Python like so

try:
    device_list = device.getDeviceList()
except:
    pass
alex-ong commented 4 years ago

I managed to get a fix:

static PyObject *
getDeviceList(PyObject *self, PyObject *args)
{
    PyObject* pyList = NULL; 

    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

    //backup; run it without multithreading.
    if (!SUCCEEDED(hr))
    {               
        hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    }

    if (SUCCEEDED(hr))
    {
        IEnumMoniker *pEnum;

        hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
        if (SUCCEEDED(hr))
        {
            pyList = DisplayDeviceInformation(pEnum);
            pEnum->Release();
        }
        CoUninitialize();
    } else {
        PyErr_SetString(PyExc_TypeError, "Could not call CoInitializeEx");      
    }

    return pyList;
}
Avasam commented 1 year ago

Related, possibly duplicate: #5

suhren commented 1 year ago

In case anyone stumbles onto this, I am still getting this error in windows-capture-device-list==1.1.0 on Windows 11.

emoto-yasushi commented 1 year ago

I am using Windows 11. Just a few code changes and this error appears. I don't know what the cause is.

In my environment, the following code gives me an error.

from distutils.dir_util import copy_tree

import device
device_list = device.getDeviceList()
print(device_list)

The following code does not produce an error.

import device
device_list = device.getDeviceList()
print(device_list)

However, it seems that not only "distutils.dir_util" is affected, but also other libraries.