Huw Davies : ole32: A presentation cache for DVASPECT_ICON must have format CF_METAFILEPICT.

Alexandre Julliard julliard at winehq.org
Tue Oct 31 13:16:02 CDT 2017


Module: wine
Branch: master
Commit: 12718fe02161358731ed19cd1e5bfe0fd122181e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=12718fe02161358731ed19cd1e5bfe0fd122181e

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Oct 31 13:23:30 2017 +0000

ole32: A presentation cache for DVASPECT_ICON must have format CF_METAFILEPICT.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ole32/datacache.c  | 22 +++++++++++++---------
 dlls/ole32/tests/ole2.c | 23 +++++++++++++++++++++++
 2 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/dlls/ole32/datacache.c b/dlls/ole32/datacache.c
index 7b33c59..2bb0948 100644
--- a/dlls/ole32/datacache.c
+++ b/dlls/ole32/datacache.c
@@ -322,19 +322,23 @@ static DataCacheEntry *DataCache_GetEntryForFormatEtc(DataCache *This, const FOR
 /* checks that the clipformat and tymed are valid and returns an error if they
 * aren't and CACHE_S_NOTSUPPORTED if they are valid, but can't be rendered by
 * DataCache_Draw */
-static HRESULT check_valid_clipformat_and_tymed(CLIPFORMAT cfFormat, DWORD tymed)
+static HRESULT check_valid_formatetc( const FORMATETC *fmt )
 {
-    if (!cfFormat || !tymed ||
-        (cfFormat == CF_METAFILEPICT && tymed == TYMED_MFPICT) ||
-        (cfFormat == CF_BITMAP && tymed == TYMED_GDI) ||
-        (cfFormat == CF_DIB && tymed == TYMED_HGLOBAL) ||
-        (cfFormat == CF_ENHMETAFILE && tymed == TYMED_ENHMF))
+    /* DVASPECT_ICON must be CF_METAFILEPICT */
+    if (fmt->dwAspect == DVASPECT_ICON && fmt->cfFormat != CF_METAFILEPICT)
+        return DV_E_FORMATETC;
+
+    if (!fmt->cfFormat || !fmt->tymed ||
+        (fmt->cfFormat == CF_METAFILEPICT && fmt->tymed == TYMED_MFPICT) ||
+        (fmt->cfFormat == CF_BITMAP && fmt->tymed == TYMED_GDI) ||
+        (fmt->cfFormat == CF_DIB && fmt->tymed == TYMED_HGLOBAL) ||
+        (fmt->cfFormat == CF_ENHMETAFILE && fmt->tymed == TYMED_ENHMF))
         return S_OK;
-    else if (tymed == TYMED_HGLOBAL)
+    else if (fmt->tymed == TYMED_HGLOBAL)
         return CACHE_S_FORMATETC_NOTSUPPORTED;
     else
     {
-        WARN("invalid clipformat/tymed combination: %d/%d\n", cfFormat, tymed);
+        WARN("invalid clipformat/tymed combination: %d/%d\n", fmt->cfFormat, fmt->tymed);
         return DV_E_TYMED;
     }
 }
@@ -368,7 +372,7 @@ static HRESULT DataCache_CreateEntry(DataCache *This, const FORMATETC *formatetc
     DWORD id = automatic ? 1 : This->last_cache_id;
     DataCacheEntry *entry;
 
-    hr = check_valid_clipformat_and_tymed(formatetc->cfFormat, formatetc->tymed);
+    hr = check_valid_formatetc( formatetc );
     if (FAILED(hr))
         return hr;
     if (hr == CACHE_S_FORMATETC_NOTSUPPORTED)
diff --git a/dlls/ole32/tests/ole2.c b/dlls/ole32/tests/ole2.c
index 509c625..4f72622 100644
--- a/dlls/ole32/tests/ole2.c
+++ b/dlls/ole32/tests/ole2.c
@@ -2309,6 +2309,29 @@ static void test_data_cache_cache(void)
     hr = IOleCache2_Uncache( cache, view_caching[0].dwConnection );
     ok( hr == S_OK, "got %08x\n", hr );
 
+    /* Only able to set cfFormat == CF_METAFILEPICT (or == 0, see above) for DVASPECT_ICON */
+    fmt.dwAspect = DVASPECT_ICON;
+    fmt.cfFormat = CF_DIB;
+    fmt.tymed = TYMED_HGLOBAL;
+    hr = IOleCache2_Cache( cache, &fmt, 0, &conn );
+    ok( hr == DV_E_FORMATETC, "got %08x\n", hr );
+    fmt.cfFormat = CF_BITMAP;
+    fmt.tymed = TYMED_GDI;
+    hr = IOleCache2_Cache( cache, &fmt, 0, &conn );
+    ok( hr == DV_E_FORMATETC, "got %08x\n", hr );
+    fmt.cfFormat = CF_ENHMETAFILE;
+    fmt.tymed = TYMED_ENHMF;
+    hr = IOleCache2_Cache( cache, &fmt, 0, &conn );
+    ok( hr == DV_E_FORMATETC, "got %08x\n", hr );
+    fmt.cfFormat = CF_METAFILEPICT;
+    fmt.tymed = TYMED_MFPICT;
+    hr = IOleCache2_Cache( cache, &fmt, 0, &conn );
+    ok( hr == S_OK, "got %08x\n", hr );
+
+    /* uncache everything */
+    hr = IOleCache2_Uncache( cache, conn );
+    ok( hr == S_OK, "got %08x\n", hr );
+
     IDataObject_Release( data );
     IOleCache2_Release( cache );
 }




More information about the wine-cvs mailing list