Signed-off-by: Mohamad Al-Jaf mohamadaljaf@gmail.com --- v2: - Support byref BSTR. - Support nested VARIANT including byref BSTR. --- dlls/propsys/propsys.spec | 2 +- dlls/propsys/propvar.c | 46 +++++++++++++++++++++++++++++++++++++++ include/propvarutil.h | 6 +++++ 3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/dlls/propsys/propsys.spec b/dlls/propsys/propsys.spec index 15749952e95..7391cf4aaa2 100644 --- a/dlls/propsys/propsys.spec +++ b/dlls/propsys/propsys.spec @@ -194,7 +194,7 @@ @ stub VariantToStringAlloc @ stub VariantToStringArray @ stub VariantToStringArrayAlloc -@ stub VariantToStringWithDefault +@ stdcall VariantToStringWithDefault(ptr wstr) @ stub VariantToUInt16 @ stub VariantToUInt16Array @ stub VariantToUInt16ArrayAlloc diff --git a/dlls/propsys/propvar.c b/dlls/propsys/propvar.c index 8f6c52f7aa7..09f9a8aa892 100644 --- a/dlls/propsys/propvar.c +++ b/dlls/propsys/propvar.c @@ -416,6 +416,52 @@ PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR p return pszDefault; }
+/****************************************************************** + * 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; +} +
/****************************************************************** * PropVariantChangeType (PROPSYS.@) diff --git a/include/propvarutil.h b/include/propvarutil.h index 36a670f56e6..2515d71b3b6 100644 --- a/include/propvarutil.h +++ b/include/propvarutil.h @@ -93,6 +93,7 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret); HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb); HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch); PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault); +PCWSTR WINAPI VariantToStringWithDefault(const VARIANT *pvar, LPCWSTR pszDefault);
HRESULT WINAPI PropVariantToStringAlloc(REFPROPVARIANT propvarIn, WCHAR **ret);
@@ -201,6 +202,11 @@ inline BOOL IsPropVariantString(REFPROPVARIANT propvar) return (PropVariantToStringWithDefault(propvar, NULL) != NULL); }
+inline BOOL IsVariantString(const VARIANT *pvar) +{ + return (VariantToStringWithDefault(pvar, NULL) != NULL); +} + #endif /* NO_PROPVAR_INLINES */ #endif /* __cplusplus */