On 3/28/22 03:16, Mohamad Al-Jaf wrote:
+/******************************************************************
- VariantToStringWithDefault (PROPSYS.@)
- */
+PCWSTR WINAPI VariantToStringWithDefault(const VARIANT *pvar, LPCWSTR pszDefault) +{
- TRACE("(%p, %s)\n", pvar, debugstr_w(pszDefault));
- switch(V_VT(pvar))
- {
case VT_BSTR:
{
if (V_BSTR(pvar) == NULL)
return L"";
return V_BSTR(pvar);
}
case VT_BYREF | VT_BSTR:
{
if (*V_BSTRREF(pvar) == NULL)
return L"";
return *V_BSTRREF(pvar);
}
case VT_BYREF | VT_VARIANT:
{
if (V_VT(V_VARIANTREF(pvar)) == VT_BSTR)
{
if (V_BSTR(V_VARIANTREF(pvar)) == NULL)
return L"";
return V_BSTR(V_VARIANTREF(pvar));
}
if (V_VT(V_VARIANTREF(pvar)) == (VT_BYREF | VT_BSTR))
{
if (*V_BSTRREF(V_VARIANTREF(pvar)) == NULL)
return L"";
return *V_BSTRREF(V_VARIANTREF(pvar));
}
}
- }
- return pszDefault;
+}
There is a lot of duplication you don't need. You can first dereference a variant if needed, and then use same path for both plain variant and variant reference. Similar for BSTR references.