I'm using Windows Media Foundation to read data from a video capture card and I'm finding that on certain machines ActivateObject returns MF_E_INVALIDMEDIATYPE. The code is pretty straightforward:
CComPtr<IMFAttributes> pAttributes = nullptr;
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
hr = MFStartup(MF_VERSION);
if (hr != S_OK)
{
return false;
}
// Create an attribute store to specify the enumeration parameters.
hr = MFCreateAttributes(&pAttributes, 1);
if (hr != S_OK)
{
return false;
}
// Source type: video capture devices
hr = pAttributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
if (hr != S_OK)
{
return false;
}
IMFActivate** ppDevices = nullptr;
bool success = true;
UINT32 count = 0;
// Enumerate devices.
HRESULT hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count);
//Returns MF_E_INVALIDMEDIATYPE on some machines (using the same device/drivers)
hr = ppDevices[0]->ActivateObject(IID_PPV_ARGS(&m_pMediaSource));