Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/combase/combase.c | 180 +++++++++++++++++++++++++ dlls/combase/combase.spec | 2 +- dlls/ole32/ole2.c | 267 -------------------------------------- dlls/ole32/ole32.spec | 2 +- 4 files changed, 182 insertions(+), 269 deletions(-)
diff --git a/dlls/combase/combase.c b/dlls/combase/combase.c index 521bfdbf834..74a76437090 100644 --- a/dlls/combase/combase.c +++ b/dlls/combase/combase.c @@ -251,3 +251,183 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT *pvar) memset(pvar, 0, sizeof(*pvar)); return hr; } + +/*********************************************************************** + * PropVariantCopy (combase.@) + */ +HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, const PROPVARIANT *pvarSrc) +{ + ULONG len; + HRESULT hr; + + TRACE("%p, %p vt %04x.\n", pvarDest, pvarSrc, pvarSrc->vt); + + hr = propvar_validatetype(pvarSrc->vt); + if (FAILED(hr)) + return DISP_E_BADVARTYPE; + + /* this will deal with most cases */ + *pvarDest = *pvarSrc; + + switch (pvarSrc->vt) + { + case VT_EMPTY: + case VT_NULL: + case VT_I1: + case VT_UI1: + case VT_I2: + case VT_UI2: + case VT_BOOL: + case VT_DECIMAL: + case VT_I4: + case VT_UI4: + case VT_R4: + case VT_ERROR: + case VT_I8: + case VT_UI8: + case VT_INT: + case VT_UINT: + case VT_R8: + case VT_CY: + case VT_DATE: + case VT_FILETIME: + break; + case VT_DISPATCH: + case VT_UNKNOWN: + case VT_STREAM: + case VT_STREAMED_OBJECT: + case VT_STORAGE: + case VT_STORED_OBJECT: + if (pvarDest->u.pStream) + IStream_AddRef(pvarDest->u.pStream); + break; + case VT_CLSID: + pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID)); + *pvarDest->u.puuid = *pvarSrc->u.puuid; + break; + case VT_LPSTR: + if (pvarSrc->u.pszVal) + { + len = strlen(pvarSrc->u.pszVal); + pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR)); + CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR)); + } + break; + case VT_LPWSTR: + if (pvarSrc->u.pwszVal) + { + len = lstrlenW(pvarSrc->u.pwszVal); + pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR)); + CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR)); + } + break; + case VT_BLOB: + case VT_BLOB_OBJECT: + if (pvarSrc->u.blob.pBlobData) + { + len = pvarSrc->u.blob.cbSize; + pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len); + CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len); + } + break; + case VT_BSTR: + pvarDest->u.bstrVal = SysAllocString(pvarSrc->u.bstrVal); + break; + case VT_CF: + if (pvarSrc->u.pclipdata) + { + len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt); + pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA)); + pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize; + pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt; + pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len); + CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len); + } + break; + default: + if (pvarSrc->vt & VT_VECTOR) + { + int elemSize; + ULONG i; + + switch (pvarSrc->vt & ~VT_VECTOR) + { + case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break; + case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break; + case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break; + case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break; + case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break; + case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break; + case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break; + case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break; + case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break; + case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break; + case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break; + case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break; + case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break; + case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break; + case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break; + case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break; + case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break; + case VT_BSTR: elemSize = sizeof(pvarSrc->u.bstrVal); break; + case VT_LPSTR: elemSize = sizeof(pvarSrc->u.pszVal); break; + case VT_LPWSTR: elemSize = sizeof(pvarSrc->u.pwszVal); break; + case VT_VARIANT: elemSize = sizeof(*pvarSrc->u.pvarVal); break; + + default: + FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR); + return E_INVALIDARG; + } + len = pvarSrc->u.capropvar.cElems; + pvarDest->u.capropvar.pElems = len ? CoTaskMemAlloc(len * elemSize) : NULL; + if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT)) + { + for (i = 0; i < len; i++) + PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]); + } + else if (pvarSrc->vt == (VT_VECTOR | VT_CF)) + { + FIXME("Copy clipformats\n"); + } + else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR)) + { + for (i = 0; i < len; i++) + pvarDest->u.cabstr.pElems[i] = SysAllocString(pvarSrc->u.cabstr.pElems[i]); + } + else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR)) + { + size_t strLen; + for (i = 0; i < len; i++) + { + strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1; + pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen); + memcpy(pvarDest->u.calpstr.pElems[i], + pvarSrc->u.calpstr.pElems[i], strLen); + } + } + else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR)) + { + size_t strLen; + for (i = 0; i < len; i++) + { + strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) * + sizeof(WCHAR); + pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen); + memcpy(pvarDest->u.calpstr.pElems[i], + pvarSrc->u.calpstr.pElems[i], strLen); + } + } + else + CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize); + } + else if (pvarSrc->vt & VT_ARRAY) + { + pvarDest->u.uhVal.QuadPart = 0; + return SafeArrayCopy(pvarSrc->u.parray, &pvarDest->u.parray); + } + else + WARN("Invalid/unsupported type %d\n", pvarSrc->vt); + } + + return S_OK; +} diff --git a/dlls/combase/combase.spec b/dlls/combase/combase.spec index 4711934dca6..70f7b17244b 100644 --- a/dlls/combase/combase.spec +++ b/dlls/combase/combase.spec @@ -280,7 +280,7 @@ @ stub NdrpFindInterface @ stdcall ProgIDFromCLSID(ptr ptr) ole32.ProgIDFromCLSID @ stdcall PropVariantClear(ptr) -@ stdcall PropVariantCopy(ptr ptr) ole32.PropVariantCopy +@ stdcall PropVariantCopy(ptr ptr) @ stub ReleaseFuncDescs @ stdcall RoActivateInstance(ptr ptr) @ stub RoCaptureErrorContext diff --git a/dlls/ole32/ole2.c b/dlls/ole32/ole2.c index 7829435244a..4f4a1378b1e 100644 --- a/dlls/ole32/ole2.c +++ b/dlls/ole32/ole2.c @@ -2730,273 +2730,6 @@ void WINAPI PropSysFreeString(LPOLESTR str) SysFreeString(str); }
-/****************************************************************************** - * Check if a PROPVARIANT's type is valid. - */ -static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt) -{ - switch (vt) - { - case VT_EMPTY: - case VT_NULL: - case VT_I1: - case VT_I2: - case VT_I4: - case VT_I8: - case VT_R4: - case VT_R8: - case VT_CY: - case VT_DATE: - case VT_BSTR: - case VT_ERROR: - case VT_BOOL: - case VT_DECIMAL: - case VT_UI1: - case VT_UI2: - case VT_UI4: - case VT_UI8: - case VT_INT: - case VT_UINT: - case VT_LPSTR: - case VT_LPWSTR: - case VT_FILETIME: - case VT_BLOB: - case VT_DISPATCH: - case VT_UNKNOWN: - case VT_STREAM: - case VT_STORAGE: - case VT_STREAMED_OBJECT: - case VT_STORED_OBJECT: - case VT_BLOB_OBJECT: - case VT_CF: - case VT_CLSID: - case VT_I1|VT_VECTOR: - case VT_I2|VT_VECTOR: - case VT_I4|VT_VECTOR: - case VT_I8|VT_VECTOR: - case VT_R4|VT_VECTOR: - case VT_R8|VT_VECTOR: - case VT_CY|VT_VECTOR: - case VT_DATE|VT_VECTOR: - case VT_BSTR|VT_VECTOR: - case VT_ERROR|VT_VECTOR: - case VT_BOOL|VT_VECTOR: - case VT_VARIANT|VT_VECTOR: - case VT_UI1|VT_VECTOR: - case VT_UI2|VT_VECTOR: - case VT_UI4|VT_VECTOR: - case VT_UI8|VT_VECTOR: - case VT_LPSTR|VT_VECTOR: - case VT_LPWSTR|VT_VECTOR: - case VT_FILETIME|VT_VECTOR: - case VT_CF|VT_VECTOR: - case VT_CLSID|VT_VECTOR: - case VT_ARRAY|VT_I1: - case VT_ARRAY|VT_UI1: - case VT_ARRAY|VT_I2: - case VT_ARRAY|VT_UI2: - case VT_ARRAY|VT_I4: - case VT_ARRAY|VT_UI4: - case VT_ARRAY|VT_INT: - case VT_ARRAY|VT_UINT: - case VT_ARRAY|VT_R4: - case VT_ARRAY|VT_R8: - case VT_ARRAY|VT_CY: - case VT_ARRAY|VT_DATE: - case VT_ARRAY|VT_BSTR: - case VT_ARRAY|VT_BOOL: - case VT_ARRAY|VT_DECIMAL: - case VT_ARRAY|VT_DISPATCH: - case VT_ARRAY|VT_UNKNOWN: - case VT_ARRAY|VT_ERROR: - case VT_ARRAY|VT_VARIANT: - return S_OK; - } - WARN("Bad type %d\n", vt); - return STG_E_INVALIDPARAMETER; -} - -/*********************************************************************** - * PropVariantCopy [OLE32.@] - */ -HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */ - const PROPVARIANT *pvarSrc) /* [in] */ -{ - ULONG len; - HRESULT hr; - - TRACE("(%p, %p vt %04x)\n", pvarDest, pvarSrc, pvarSrc->vt); - - hr = PROPVARIANT_ValidateType(pvarSrc->vt); - if (FAILED(hr)) - return DISP_E_BADVARTYPE; - - /* this will deal with most cases */ - *pvarDest = *pvarSrc; - - switch(pvarSrc->vt) - { - case VT_EMPTY: - case VT_NULL: - case VT_I1: - case VT_UI1: - case VT_I2: - case VT_UI2: - case VT_BOOL: - case VT_DECIMAL: - case VT_I4: - case VT_UI4: - case VT_R4: - case VT_ERROR: - case VT_I8: - case VT_UI8: - case VT_INT: - case VT_UINT: - case VT_R8: - case VT_CY: - case VT_DATE: - case VT_FILETIME: - break; - case VT_DISPATCH: - case VT_UNKNOWN: - case VT_STREAM: - case VT_STREAMED_OBJECT: - case VT_STORAGE: - case VT_STORED_OBJECT: - if (pvarDest->u.pStream) - IStream_AddRef(pvarDest->u.pStream); - break; - case VT_CLSID: - pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID)); - *pvarDest->u.puuid = *pvarSrc->u.puuid; - break; - case VT_LPSTR: - if (pvarSrc->u.pszVal) - { - len = strlen(pvarSrc->u.pszVal); - pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR)); - CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR)); - } - break; - case VT_LPWSTR: - if (pvarSrc->u.pwszVal) - { - len = lstrlenW(pvarSrc->u.pwszVal); - pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR)); - CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR)); - } - break; - case VT_BLOB: - case VT_BLOB_OBJECT: - if (pvarSrc->u.blob.pBlobData) - { - len = pvarSrc->u.blob.cbSize; - pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len); - CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len); - } - break; - case VT_BSTR: - pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal); - break; - case VT_CF: - if (pvarSrc->u.pclipdata) - { - len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt); - pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA)); - pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize; - pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt; - pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len); - CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len); - } - break; - default: - if (pvarSrc->vt & VT_VECTOR) - { - int elemSize; - ULONG i; - - switch(pvarSrc->vt & ~VT_VECTOR) - { - case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break; - case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break; - case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break; - case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break; - case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break; - case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break; - case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break; - case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break; - case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break; - case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break; - case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break; - case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break; - case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break; - case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break; - case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break; - case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break; - case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break; - case VT_BSTR: elemSize = sizeof(pvarSrc->u.bstrVal); break; - case VT_LPSTR: elemSize = sizeof(pvarSrc->u.pszVal); break; - case VT_LPWSTR: elemSize = sizeof(pvarSrc->u.pwszVal); break; - case VT_VARIANT: elemSize = sizeof(*pvarSrc->u.pvarVal); break; - - default: - FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR); - return E_INVALIDARG; - } - len = pvarSrc->u.capropvar.cElems; - pvarDest->u.capropvar.pElems = len ? CoTaskMemAlloc(len * elemSize) : NULL; - if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT)) - { - for (i = 0; i < len; i++) - PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]); - } - else if (pvarSrc->vt == (VT_VECTOR | VT_CF)) - { - FIXME("Copy clipformats\n"); - } - else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR)) - { - for (i = 0; i < len; i++) - pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]); - } - else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR)) - { - size_t strLen; - for (i = 0; i < len; i++) - { - strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1; - pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen); - memcpy(pvarDest->u.calpstr.pElems[i], - pvarSrc->u.calpstr.pElems[i], strLen); - } - } - else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR)) - { - size_t strLen; - for (i = 0; i < len; i++) - { - strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) * - sizeof(WCHAR); - pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen); - memcpy(pvarDest->u.calpstr.pElems[i], - pvarSrc->u.calpstr.pElems[i], strLen); - } - } - else - CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize); - } - else if (pvarSrc->vt & VT_ARRAY) - { - pvarDest->u.uhVal.QuadPart = 0; - return SafeArrayCopy(pvarSrc->u.parray, &pvarDest->u.parray); - } - else - WARN("Invalid/unsupported type %d\n", pvarSrc->vt); - } - - return S_OK; -} - /****************************************************************************** * DllDebugObjectRPCHook (OLE32.@) * turns on and off internal debugging, pointer is only used on macintosh diff --git a/dlls/ole32/ole32.spec b/dlls/ole32/ole32.spec index 86b4023081c..6699d797b02 100644 --- a/dlls/ole32/ole32.spec +++ b/dlls/ole32/ole32.spec @@ -242,7 +242,7 @@ @ stdcall PropSysAllocString(wstr) @ stdcall PropSysFreeString(wstr) @ stdcall PropVariantClear(ptr) combase.PropVariantClear -@ stdcall PropVariantCopy(ptr ptr) +@ stdcall PropVariantCopy(ptr ptr) combase.PropVariantCopy @ stdcall ReadClassStg(ptr ptr) @ stdcall ReadClassStm(ptr ptr) @ stdcall ReadFmtUserTypeStg(ptr ptr ptr)