From: Akihiro Sagawa sagawa.aki@gmail.com
--- dlls/shell32/shellole.c | 66 ++++++++++++++++++++--------------- dlls/shell32/tests/shellole.c | 3 -- 2 files changed, 37 insertions(+), 32 deletions(-)
diff --git a/dlls/shell32/shellole.c b/dlls/shell32/shellole.c index 055244b1e67..0ee5c95402b 100644 --- a/dlls/shell32/shellole.c +++ b/dlls/shell32/shellole.c @@ -621,50 +621,58 @@ UINT WINAPI DragQueryFileW( LPWSTR lpszwFile, UINT lLength) { - LPWSTR lpwDrop; + LPWSTR buffer = NULL; + LPCWSTR filename; UINT i = 0; - DROPFILES *lpDropFileStruct = GlobalLock(hDrop); + const DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
if(!lpDropFileStruct) goto end;
- lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles); - - if(lpDropFileStruct->fWide == FALSE) { - LPSTR lpszFileA = NULL; - - if(lpszwFile && lFile != 0xFFFFFFFF) { - lpszFileA = malloc(lLength); - if(lpszFileA == NULL) { + if(lpDropFileStruct->fWide) + { + LPCWSTR p = (LPCWSTR) ((LPCSTR)lpDropFileStruct + lpDropFileStruct->pFiles); + while (i++ < lFile) + { + while (*p++); /* skip filename */ + if (!*p) + { + i = (lFile == 0xFFFFFFFF) ? i : 0; goto end; } } - i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength); - - if(lpszFileA) { - MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength); - free(lpszFileA); + filename = p; + } + else + { + LPCSTR p = (LPCSTR)lpDropFileStruct + lpDropFileStruct->pFiles; + while (i++ < lFile) + { + while (*p++); /* skip filename */ + if (!*p) + { + i = (lFile == 0xFFFFFFFF) ? i : 0; + goto end; + } } - goto end; + i = MultiByteToWideChar(CP_ACP, 0, p, -1, NULL, 0); + buffer = malloc(i * sizeof(WCHAR)); + if (!buffer) + { + i = 0; + goto end; + } + MultiByteToWideChar(CP_ACP, 0, p, -1, buffer, i); + filename = buffer; }
- i = 0; - while (i++ < lFile) - { - while (*lpwDrop++); /* skip filename */ - if (!*lpwDrop) - { - i = (lFile == 0xFFFFFFFF) ? i : 0; - goto end; - } - } - - i = lstrlenW(lpwDrop); + i = lstrlenW(filename); if ( !lpszwFile) goto end; /* needed buffer size */ - lstrcpynW (lpszwFile, lpwDrop, lLength); + lstrcpynW(lpszwFile, filename, lLength); end: GlobalUnlock(hDrop); + free(buffer); return i; }
diff --git a/dlls/shell32/tests/shellole.c b/dlls/shell32/tests/shellole.c index 0b1146ba8bb..7d1204d1c1f 100644 --- a/dlls/shell32/tests/shellole.c +++ b/dlls/shell32/tests/shellole.c @@ -809,16 +809,13 @@ static LRESULT WINAPI drop_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARA
len = wcslen(expected_filenameW); num = DragQueryFileW(hDrop, 0, NULL, 0); - todo_wine_if(expected_filename[0] == 'd' && !(flags & DROP_WIDE_FILENAME)) ok(num == len, "expected %u, got %u\n", len, num);
num = DragQueryFileW(hDrop, 0, filenameW, 0); - todo_wine_if(expected_filename[0] == 'd' && !(flags & DROP_WIDE_FILENAME)) ok(num == len, "expected %u, got %u\n", len, num); ok(!wcscmp(filenameW, L"dummy"), "got %s\n", wine_dbgstr_w(filenameW));
num = DragQueryFileW(hDrop, 0, filenameW, ARRAY_SIZE(filename)); - todo_wine_if(expected_filename[0] == 'd' && !(flags & DROP_WIDE_FILENAME)) ok(num == len, "expected %u, got %u\n", len, num); ok(!wcscmp(filenameW, expected_filenameW), "expected %s, got %s\n", wine_dbgstr_w(expected_filenameW), wine_dbgstr_w(filenameW));