Merge 51053, 51069
[reactos.git] / reactos / dll / win32 / shell32 / clipboard.c
index 1bdae63..24fd0d0 100644 (file)
@@ -47,52 +47,56 @@ WINE_DEFAULT_DEBUG_CHANNEL(shell);
 HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
 {
        UINT i;
-       int rootlen = 0,size = 0;
-       WCHAR wszRootPath[MAX_PATH];
+       int size = 0;
        WCHAR wszFileName[MAX_PATH];
-       HGLOBAL hGlobal;
+       HGLOBAL hGlobal = NULL;
        DROPFILES *pDropFiles;
        int offset;
+       LPITEMIDLIST *pidls;
 
        TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
 
+       pidls = HeapAlloc(GetProcessHeap(), 0, cidl * sizeof(*pidls));
+       if (!pidls)
+               goto cleanup;
+
        /* get the size needed */
        size = sizeof(DROPFILES);
 
-       SHGetPathFromIDListW(pidlRoot, wszRootPath);
-       PathAddBackslashW(wszRootPath);
-       rootlen = wcslen(wszRootPath);
-
        for (i=0; i<cidl;i++)
        {
-         _ILSimpleGetTextW(apidl[i], wszFileName, MAX_PATH);
-         size += (rootlen + wcslen(wszFileName) + 1) * sizeof(WCHAR);
+         pidls[i] = ILCombine(pidlRoot, apidl[i]);
+         SHGetPathFromIDListW(pidls[i], wszFileName);
+         size += (wcslen(wszFileName) + 1) * sizeof(WCHAR);
        }
 
        size += sizeof(WCHAR);
 
        /* Fill the structure */
        hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
-       if(!hGlobal) return hGlobal;
+       if(!hGlobal)
+               goto cleanup;
 
         pDropFiles = (DROPFILES *)GlobalLock(hGlobal);
        offset = (sizeof(DROPFILES) + sizeof(WCHAR) - 1) / sizeof(WCHAR);
         pDropFiles->pFiles = offset * sizeof(WCHAR);
         pDropFiles->fWide = TRUE;
 
-       wcscpy(wszFileName, wszRootPath);
-
        for (i=0; i<cidl;i++)
        {
-
-         _ILSimpleGetTextW(apidl[i], wszFileName + rootlen, MAX_PATH - rootlen);
+         SHGetPathFromIDListW(pidls[i], wszFileName);
          wcscpy(((WCHAR*)pDropFiles)+offset, wszFileName);
          offset += wcslen(wszFileName) + 1;
+         ILFree(pidls[i]);
        }
 
        ((WCHAR*)pDropFiles)[offset] = 0;
        GlobalUnlock(hGlobal);
 
+cleanup:
+       if(pidls)
+               HeapFree(GetProcessHeap(), 0, pidls);
+
        return hGlobal;
 }