From 517bb10261069abd3ffd642dddd6338b7cacd094 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 15 May 2016 19:08:44 +0200
Subject: oleaut32: Implement SaveAsFile for PICTYPE_ENHMETAFILE.

---
 dlls/oleaut32/olepicture.c       | 17 +++++++++++++++--
 dlls/oleaut32/tests/olepicture.c |  3 ---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/dlls/oleaut32/olepicture.c b/dlls/oleaut32/olepicture.c
index 7d13942..db90c4c 100644
--- a/dlls/oleaut32/olepicture.c
+++ b/dlls/oleaut32/olepicture.c
@@ -1961,9 +1961,22 @@ static HRESULT WINAPI OLEPictureImpl_SaveAsFile(IPicture *iface,
     case PICTYPE_METAFILE:
         FIXME("PICTYPE_METAFILE is not implemented\n");
         return E_NOTIMPL;
+
     case PICTYPE_ENHMETAFILE:
-        FIXME("ENHMETAFILE is not implemented\n");
-        return E_NOTIMPL;
+        if (!mem_copy) return E_FAIL;
+
+        if (This->bIsDirty || !This->data)
+        {
+            if (!serializeEMF(This->desc.u.emf.hemf, &data, &data_size))
+                return E_FAIL;
+            HeapFree(GetProcessHeap(), 0, This->data);
+            This->data = data;
+            This->datalen = data_size;
+        }
+        hr = IStream_Write(stream, This->data, This->datalen, &written);
+        if (hr == S_OK && size) *size = written;
+        return hr;
+
     default:
         FIXME("%#x is not implemented\n", This->desc.picType);
         break;
diff --git a/dlls/oleaut32/tests/olepicture.c b/dlls/oleaut32/tests/olepicture.c
index 29d787e..7b1178e 100644
--- a/dlls/oleaut32/tests/olepicture.c
+++ b/dlls/oleaut32/tests/olepicture.c
@@ -1338,7 +1338,6 @@ static void test_load_save_emf(void)
     size = -1;
     hr = IPicture_SaveAsFile(pic, dst_stream, TRUE, &size);
     ok(hr == S_OK, "IPicture_SaveasFile error %#x\n", hr);
-todo_wine
     ok(size == 128, "expected 128, got %d\n", size);
     emh = GlobalLock(hmem);
 if (size)
@@ -1350,9 +1349,7 @@ if (size)
 
     size = -1;
     hr = IPicture_SaveAsFile(pic, dst_stream, FALSE, &size);
-todo_wine
     ok(hr == E_FAIL, "expected E_FAIL, got %#x\n", hr);
-todo_wine
     ok(size == -1, "expected -1, got %d\n", size);
 
     offset.QuadPart = 0;
-- 
2.8.0

