Search code examples
c++comdirectshow

Cannot release IUnkown object, getting error: HRESULT: "The system cannot find the file specified"


I am trying to 'release' some IUnkown COM objects but I get the error:

hr = 0x00000002 : The system cannot find the file specified.

This happens when I try to release a moniker and/or a propertybag object. I have simplified the code in order to simplify the problem. My code works up till where I call BindToStorage (this call returns S_OK) yet when I call release I get my error.

IEnumMoniker *pEnum;
HRESULT hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);

IMoniker *pMoniker = NULL;
IPropertyBag *pPropBag = NULL;

if(pEnum->Next(1, &pMoniker, NULL) == S_OK){
    hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
    hr = pPropBag->Release();
    hr = pMoniker->Release();
}

Any ideas?


Solution

  • IUnknown::Release returns outstanding reference count, not HRESULT. The value of two is valid and you are supposed to simply ignore it. It does not mean there there is a file error or otherwise "The system cannot find the file specified." This behavior is documented - standard COM behavior, see MSDN for details.