On 5/5/19 6:10 PM, Andreas Maier wrote:
/* Try to get a IEnumVARIANT by _NewEnum */
hres = IDispatch_Invoke(obj,
DISPID_NEWENUM, &IID_NULL, LOCALE_NEUTRAL,
DISPATCH_METHOD, &dispparams, &varresult,
NULL, NULL);
if (FAILED(hres))
{
ERR("Enumerator: no DISPID_NEWENUM.\n");
hres = E_INVALIDARG;
goto cleanuperr;
}
if (V_VT(&varresult) == VT_DISPATCH)
{
enumvar = (IEnumVARIANT*)V_DISPATCH(&varresult);
VariantClear(&varresult);
}
else if (V_VT(&varresult) == VT_UNKNOWN)
{
hres = IUnknown_QueryInterface(V_UNKNOWN(&varresult),
&IID_IEnumVARIANT, (void**)&enumvar);
if (FAILED(hres))
{
hres = E_INVALIDARG;
goto cleanuperr;
}
enumvar = (IEnumVARIANT*)V_DISPATCH(&varresult);
VariantClear(&varresult);
}
else
{
ERR("Enumerator: NewEnum unexpected type of varresult (%d).\n", V_VT(&varresult));
hres = E_INVALIDARG;
goto cleanuperr;
}
This looks too complicated, you don't need to handle VT_UNKNOWN vs VT_DISPATCH differently, simply QI for IEnumVARIANT when you got either of those. Also you immediately free varresult after assigning it, that's wrong; for VT_UNKNOWN case you overwrite QI result with same original pointer.
Additionally, 'isnull' field seems to be redundant.