STDMETHODIMP UDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect) { GuiLock __; LLOG("DragEnter " << pt); data = pDataObj; data->AddRef(); fmt.Clear(); IEnumFORMATETC *fe; if(!ctrl || pDataObj->EnumFormatEtc(DATADIR_GET, &fe) != NOERROR) { *pdwEffect = DROPEFFECT_NONE; return NOERROR; } FORMATETC fmtetc; while(fe->Next(1, &fmtetc, 0) == S_OK) { fmt.FindAdd(FromWin32CF(fmtetc.cfFormat)); if(fmtetc.ptd) CoTaskMemFree(fmtetc.ptd); } fe->Release(); DnD(pt, false, pdwEffect, grfKeyState); return NOERROR; }
void COleServerItem::AddOtherClipboardData(COleDataSource* pDataSource) { ASSERT_VALID(this); ASSERT_VALID(pDataSource); // get IEnumFORMATETC interface for the IDataObject LPDATAOBJECT lpDataObject = GetDataObject(); LPENUMFORMATETC lpEnumFORMATETC; if (lpDataObject->EnumFormatEtc(DATADIR_GET, &lpEnumFORMATETC) != S_OK) return; ASSERT(lpEnumFORMATETC != NULL); // get all formats that the object will give us FORMATETC formatEtc; while (lpEnumFORMATETC->Next(1, &formatEtc, NULL) == S_OK) { STGMEDIUM stgMedium; if (lpDataObject->GetData(&formatEtc, &stgMedium) != S_OK) { // data is not available CoTaskMemFree(formatEtc.ptd); } else if (stgMedium.pUnkForRelease != NULL) { // don't cache data with pUnkForRelease != NULL ::ReleaseStgMedium(&stgMedium); CoTaskMemFree(formatEtc.ptd); } else { // cache the data (now we own the stgMedium) pDataSource->CacheData(0, &stgMedium, &formatEtc); } } // cleanup lpEnumFORMATETC->Release(); }
STDMETHODIMP CDDShellExt::Initialize(LPCITEMIDLIST pidlFolder,LPDATAOBJECT pDO,HKEY hProgID) { (void)hProgID; if(!connected) { bool b = m_ac.connectToServer(); if (b==true) { connected=true; } else return E_FAIL; } FORMATETC fmt={CF_HDROP,NULL,DVASPECT_CONTENT,-1,TYMED_HGLOBAL}; STGMEDIUM stg={TYMED_HGLOBAL}; HDROP hDrop; fDestDir[0]=0; if (!SHGetPathFromIDList(pidlFolder,fDestDir)) { #ifdef CATCHCOPY_EXPLORER_PLUGIN_DEBUG MessageBox(NULL,L"Initialize",L"E_FAIL 1",MB_OK); #endif // CATCHCOPY_EXPLORER_PLUGIN_DEBUG return E_FAIL; } // Detect if it's explorer that started the operation by enumerating available // clipboard formats and searching for one that only explorer uses IEnumFORMATETC *en; FORMATETC fmt2; WCHAR fmtName[256]=L"\0"; fFromExplorer=false; pDO->EnumFormatEtc(DATADIR_GET,&en); while(en->Next(1,&fmt2,NULL)==S_OK){ GetClipboardFormatName(fmt2.cfFormat,fmtName,256); if (!wcscmp(fmtName,CFSTR_SHELLIDLIST)) fFromExplorer=true; } en->Release(); // Look for CF_HDROP data in the data object. If there // is no such data, return an error back to Explorer. if (FAILED(pDO->GetData(&fmt,&stg))) { #ifdef CATCHCOPY_EXPLORER_PLUGIN_DEBUG MessageBox(NULL,L"Initialize",L"E_INVALIDARG 2",MB_OK); #endif // CATCHCOPY_EXPLORER_PLUGIN_DEBUG return E_INVALIDARG; } // Get a pointer to the actual data. hDrop=(HDROP)GlobalLock(stg.hGlobal); // Make sure it worked. if (hDrop==NULL) { #ifdef CATCHCOPY_EXPLORER_PLUGIN_DEBUG MessageBox(NULL,L"Initialize",L"E_INVALIDARG 1",MB_OK); #endif // CATCHCOPY_EXPLORER_PLUGIN_DEBUG return E_INVALIDARG; } UINT numFiles,i; WCHAR fn[MAX_PATH]=L""; numFiles=DragQueryFile(hDrop,0xFFFFFFFF,NULL,0); if (numFiles) { for(i=0;i<numFiles;++i) { if(DragQueryFile(hDrop,i,fn,MAX_PATH)) sources.push_back(fn); } } GlobalUnlock(stg.hGlobal); ReleaseStgMedium(&stg); return S_OK; }