Here is a sample code that creates a COM object:
CComPtr<IBaseFilter> pFilter; auto hr = CoCreateInstance(CLSID_DMOWrapperFilter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void**>(&pFilter));
I saw somewhere that checking that CoCreateInstance() succeeded should look like this:
if (SUCCEEDED(hr) && pFilter != nullptr) {
What if I would check only hr ? Wouldn't it be enough? Should I also check that filter != nullptr ?
//would this be enough? if (SUCCEEDED(hr)) { // code goes here }
This question also applies to other COM methods, such as QueryInterface() .
source share