HRESULT SH_GetApidlFromDataObject(IDataObject *pDataObject, PIDLIST_ABSOLUTE* ppidlfolder, PUITEMID_CHILD **apidlItems, UINT *pcidl) { UINT cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLIST); if (!cfShellIDList) return E_FAIL; FORMATETC fmt; InitFormatEtc (fmt, cfShellIDList, TYMED_HGLOBAL); HRESULT hr = pDataObject->QueryGetData(&fmt); if (FAILED_UNEXPECTEDLY(hr)) return hr; STGMEDIUM medium; hr = pDataObject->GetData(&fmt, &medium); if (FAILED_UNEXPECTEDLY(hr)) return hr; /* lock the handle */ LPIDA lpcida = (LPIDA)GlobalLock(medium.hGlobal); if (!lpcida) { ReleaseStgMedium(&medium); return E_FAIL; } /* convert the data into pidl */ LPITEMIDLIST pidl; LPITEMIDLIST *apidl = _ILCopyCidaToaPidl(&pidl, lpcida); if (!apidl) { ReleaseStgMedium(&medium); return E_OUTOFMEMORY; } *ppidlfolder = pidl; *apidlItems = apidl; *pcidl = lpcida->cidl; ReleaseStgMedium(&medium); return S_OK; }
static BOOL DoPaste(ContextMenu *This) { BOOL bSuccess = FALSE; IDataObject * pda; TRACE("\n"); if(SUCCEEDED(OleGetClipboard(&pda))) { STGMEDIUM medium; FORMATETC formatetc; TRACE("pda=%p\n", pda); /* Set the FORMATETC structure*/ InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), TYMED_HGLOBAL); /* Get the pidls from IDataObject */ if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium))) { LPITEMIDLIST * apidl; LPITEMIDLIST pidl; IShellFolder *psfFrom = NULL, *psfDesktop; LPIDA lpcida = GlobalLock(medium.u.hGlobal); TRACE("cida=%p\n", lpcida); apidl = _ILCopyCidaToaPidl(&pidl, lpcida); /* bind to the source shellfolder */ SHGetDesktopFolder(&psfDesktop); if(psfDesktop) { IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom); IShellFolder_Release(psfDesktop); } if (psfFrom) { /* get source and destination shellfolder */ ISFHelper *psfhlpdst, *psfhlpsrc; IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&psfhlpdst); IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (void**)&psfhlpsrc); /* do the copy/move */ if (psfhlpdst && psfhlpsrc) { ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl); /* FIXME handle move ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl); */ } if(psfhlpdst) ISFHelper_Release(psfhlpdst); if(psfhlpsrc) ISFHelper_Release(psfhlpsrc); IShellFolder_Release(psfFrom); } _ILFreeaPidl(apidl, lpcida->cidl); SHFree(pidl); /* release the medium*/ ReleaseStgMedium(&medium); } IDataObject_Release(pda); } #if 0 HGLOBAL hMem; OpenClipboard(NULL); hMem = GetClipboardData(CF_HDROP); if(hMem) { char * pDropFiles = GlobalLock(hMem); if(pDropFiles) { int len, offset = sizeof(DROPFILESTRUCT); while( pDropFiles[offset] != 0) { len = strlen(pDropFiles + offset); TRACE("%s\n", pDropFiles + offset); offset += len+1; } } GlobalUnlock(hMem); } CloseClipboard(); #endif return bSuccess; }