From 0a5086ab64f2c35e2f462cf4e77118733a80f2a2 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Mon, 27 Aug 2012 17:28:23 -0500 Subject: [PATCH] ole32: Add support for reading BSTR properties. --- dlls/ole32/stg_prop.c | 35 +++++++++++++++++++++++++++++++++++ dlls/ole32/tests/propvariant.c | 10 ++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/dlls/ole32/stg_prop.c b/dlls/ole32/stg_prop.c index 103f14511da..d7d340fe614 100644 --- a/dlls/ole32/stg_prop.c +++ b/dlls/ole32/stg_prop.c @@ -58,6 +58,7 @@ #include "dictionary.h" #include "storage32.h" #include "enumx.h" +#include "oleauto.h" WINE_DEFAULT_DEBUG_CHANNEL(storage); @@ -1125,6 +1126,40 @@ static HRESULT PropertyStorage_ReadProperty(PROPVARIANT *prop, const BYTE *data, } break; } + case VT_BSTR: + { + DWORD count, wcount; + + StorageUtl_ReadDWord(data, 0, &count); + if (codepage == CP_UNICODE && count % 2) + { + WARN("Unicode string has odd number of bytes\n"); + hr = STG_E_INVALIDHEADER; + } + else + { + if (codepage == CP_UNICODE) + wcount = count / 2; + else + wcount = MultiByteToWideChar(codepage, 0, (LPCSTR)(data + sizeof(DWORD)), count, NULL, 0); + + prop->u.bstrVal = SysAllocStringLen(NULL, wcount); /* FIXME: use allocator? */ + + if (prop->u.bstrVal) + { + if (codepage == CP_UNICODE) + memcpy(prop->u.bstrVal, data + sizeof(DWORD), count); + else + MultiByteToWideChar(codepage, 0, (LPCSTR)(data + sizeof(DWORD)), count, prop->u.bstrVal, wcount); + + prop->u.bstrVal[wcount - 1] = '\0'; + TRACE("Read string value %s\n", debugstr_w(prop->u.bstrVal)); + } + else + hr = STG_E_INSUFFICIENTMEMORY; + } + break; + } case VT_BLOB: { DWORD count; diff --git a/dlls/ole32/tests/propvariant.c b/dlls/ole32/tests/propvariant.c index ec1dfd7af56..5f7adba1dce 100644 --- a/dlls/ole32/tests/propvariant.c +++ b/dlls/ole32/tests/propvariant.c @@ -395,18 +395,16 @@ static void test_propertytovariant(void) CP_WINUNICODE, &propvar, &allocator); ok(ret == 0, "StgConvertPropertyToVariant returned %i\n", ret); - todo_wine ok(propvar.vt == VT_BSTR, "unexpected vt %x\n", propvar.vt); - if (propvar.vt == VT_BSTR) - ok(!lstrcmpW(U(propvar).bstrVal, test_string), "unexpected string value\n"); + ok(propvar.vt == VT_BSTR, "unexpected vt %x\n", propvar.vt); + ok(!lstrcmpW(U(propvar).bstrVal, test_string), "unexpected string value\n"); PropVariantClear(&propvar); ret = pStgConvertPropertyToVariant((SERIALIZEDPROPERTYVALUE*)serialized_bstr_mb, CP_UTF8, &propvar, &allocator); ok(ret == 0, "StgConvertPropertyToVariant returned %i\n", ret); - todo_wine ok(propvar.vt == VT_BSTR, "unexpected vt %x\n", propvar.vt); - if (propvar.vt == VT_BSTR) - ok(!lstrcmpW(U(propvar).bstrVal, test_string), "unexpected string value\n"); + ok(propvar.vt == VT_BSTR, "unexpected vt %x\n", propvar.vt); + ok(!lstrcmpW(U(propvar).bstrVal, test_string), "unexpected string value\n"); PropVariantClear(&propvar); } -- 2.11.4.GIT