Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/ole32/clipboard.c | 1 + dlls/ole32/tests/clipboard.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
diff --git a/dlls/ole32/clipboard.c b/dlls/ole32/clipboard.c index a28dcef9eee..614d67b0f66 100644 --- a/dlls/ole32/clipboard.c +++ b/dlls/ole32/clipboard.c @@ -1135,6 +1135,7 @@ static DWORD get_tymed_from_nonole_cf(UINT cf)
switch(cf) { + case CF_HDROP: case CF_TEXT: case CF_OEMTEXT: case CF_UNICODETEXT: diff --git a/dlls/ole32/tests/clipboard.c b/dlls/ole32/tests/clipboard.c index 0a087aff840..3c44fdec5b2 100644 --- a/dlls/ole32/tests/clipboard.c +++ b/dlls/ole32/tests/clipboard.c @@ -28,6 +28,8 @@ #include "windef.h" #include "winbase.h" #include "objbase.h" +#include "shellapi.h" +#include "shlobj.h"
#include "wine/test.h"
@@ -1513,6 +1515,27 @@ static HENHMETAFILE create_emf(void) return CloseEnhMetaFile(hdc); }
+static HDROP create_dropped_file(void) +{ + WCHAR path[] = L"C:\testfile1"; + DROPFILES *dropfiles; + DWORD size, offset; + HDROP hdrop; + + size = sizeof(DROPFILES) + (sizeof(path) + 1) * sizeof(WCHAR); + offset = sizeof(DROPFILES); + hdrop = GlobalAlloc(GHND, size); + dropfiles = GlobalLock(hdrop); + dropfiles->pFiles = offset; + dropfiles->fWide = TRUE; + lstrcpyW(((WCHAR *)dropfiles) + offset, path); + offset += lstrlenW(path) + 1; + ((WCHAR *)dropfiles)[offset] = 0; + GlobalUnlock(hdrop); + + return hdrop; +} + static void test_nonole_clipboard(void) { HRESULT hr; @@ -1524,6 +1547,7 @@ static void test_nonole_clipboard(void) HENHMETAFILE emf; STGMEDIUM med; DWORD obj_type; + HDROP hdrop;
r = OpenClipboard(NULL); ok(r, "gle %d\n", GetLastError()); @@ -1552,6 +1576,7 @@ static void test_nonole_clipboard(void) hblob = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE|GMEM_ZEROINIT, 10); emf = create_emf(); hstorage = create_storage(); + hdrop = create_dropped_file();
r = OpenClipboard(NULL); ok(r, "gle %d\n", GetLastError()); @@ -1563,6 +1588,8 @@ static void test_nonole_clipboard(void) ok(h == emf, "got %p\n", h); h = SetClipboardData(cf_storage, hstorage); ok(h == hstorage, "got %p\n", h); + h = SetClipboardData(CF_HDROP, hdrop); + ok(h == hdrop, "got %p\n", h); r = CloseClipboard(); ok(r, "gle %d\n", GetLastError());
@@ -1608,6 +1635,14 @@ static void test_nonole_clipboard(void) ok(fmt.lindex == -1, "lindex %d\n", fmt.lindex); ok(fmt.tymed == (TYMED_ISTREAM | TYMED_HGLOBAL), "tymed %x\n", fmt.tymed);
+ hr = IEnumFORMATETC_Next(enum_fmt, 1, &fmt, NULL); + ok(hr == S_OK, "got %08x\n", hr); + ok(fmt.cfFormat == CF_HDROP, "cf %04x\n", fmt.cfFormat); + ok(fmt.ptd == NULL, "ptd %p\n", fmt.ptd); + ok(fmt.dwAspect == DVASPECT_CONTENT, "aspect %x\n", fmt.dwAspect); + ok(fmt.lindex == -1, "lindex %d\n", fmt.lindex); + ok(fmt.tymed == (TYMED_ISTREAM | TYMED_HGLOBAL), "tymed %x\n", fmt.tymed); + hr = IEnumFORMATETC_Next(enum_fmt, 1, &fmt, NULL); ok(hr == S_OK, "got %08x\n", hr); /* User32 adds some synthesised formats */
On Tue, Mar 09, 2021 at 11:57:01AM +0800, Jactry Zeng wrote:
+static HDROP create_dropped_file(void) +{
- WCHAR path[] = L"C:\testfile1";
You need to escape the backslash. Also, it would most likely be easier to include the second \0 in the string ie. L"C:\testfile1\0" and then use memcpy to copy it.
- DROPFILES *dropfiles;
- DWORD size, offset;
- HDROP hdrop;
- size = sizeof(DROPFILES) + (sizeof(path) + 1) * sizeof(WCHAR);
This is wrong.
- offset = sizeof(DROPFILES);
- hdrop = GlobalAlloc(GHND, size);
- dropfiles = GlobalLock(hdrop);
- dropfiles->pFiles = offset;
- dropfiles->fWide = TRUE;
- lstrcpyW(((WCHAR *)dropfiles) + offset, path);
As is this - offset is a byte offset...
- offset += lstrlenW(path) + 1;
...which seems to turn into a WCHAR offset.
- ((WCHAR *)dropfiles)[offset] = 0;
- GlobalUnlock(hdrop);
- return hdrop;
+}
Hi Huw,
I sent another try. Thanks for the review!
On 3/9/21 8:48 PM, Huw Davies wrote:
On Tue, Mar 09, 2021 at 11:57:01AM +0800, Jactry Zeng wrote:
+static HDROP create_dropped_file(void) +{
- WCHAR path[] = L"C:\testfile1";
You need to escape the backslash. Also, it would most likely be easier to include the second \0 in the string ie. L"C:\testfile1\0" and then use memcpy to copy it.
- DROPFILES *dropfiles;
- DWORD size, offset;
- HDROP hdrop;
- size = sizeof(DROPFILES) + (sizeof(path) + 1) * sizeof(WCHAR);
This is wrong.
- offset = sizeof(DROPFILES);
- hdrop = GlobalAlloc(GHND, size);
- dropfiles = GlobalLock(hdrop);
- dropfiles->pFiles = offset;
- dropfiles->fWide = TRUE;
- lstrcpyW(((WCHAR *)dropfiles) + offset, path);
As is this - offset is a byte offset...
- offset += lstrlenW(path) + 1;
...which seems to turn into a WCHAR offset.
- ((WCHAR *)dropfiles)[offset] = 0;
- GlobalUnlock(hdrop);
- return hdrop;
+}