CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR clipboard formats
Hello!
I'm developing an NSE using ATL and C++ on VS2003 and trying to support the
CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR clipboard formats to support
copying from my NSE to Explorer. I'm trying to use these CF's since they were
suggested as the solution to one of my problems by some people on this forum.
I've looked at the documentation and tried to figure out how to use them, but
apparently with no success. I face a problem already when
CFSTR_FILEDESCRIPTOR is used to display the context menu to allow pasting:
All I get is that just 'Paste shortcut' is enabled on the context menu. I'm
pretty sure I do something wrong when specifying the names of the files to
move (by the way, the files don't exist yet on my PC, so I just specify
placeholder names, they'll be retrieved when 'Paste' is selected, as a ersult
of CFSTR_FILECONTENTS being used)
Following is the code I use in my IDataObject::GetData method, in the case
of CFSTR_FILEDESCRIPTOR.
if (pFormatetc->cfFormat == RegisterClipboardFormat(CFSTR_FILECONTENTS)){
// ... Er... we'll see what happens here...
return S_OK;
}else if (pFormatetc->cfFormat ==
RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR)){
UINT bytesToAllocate=0;
UINT j=0;
LPTSTR* filesToRequest=new
LPTSTR[this->m_numberOfItems];
DWORD length=MAX_PATH;
FILEDESCRIPTOR* descriptors = new
FILEDESCRIPTOR[this->m_numberOfItems]; // To fill the FILEGROUPDESCRIPTOR
for(int i=0; i<this->m_numberOfItems; i++){
LPITEMIDLIST tempPidl =
m_PidlMgr.GetLastItem(m_pidl[i]);
filesToRequest[i]=new TCHAR[MAX_PATH];
m_PidlMgr.GetName(tempPidl,filesToRequest[i]);
.....
bytesToAllocate+=(_tcslen(filesToRequest[i])+1); // Add 1 to
keep track of
the ending \0
_tcscpy(descriptors[i].cFileName,
filesToRequest[i]);
}
HGLOBAL hgDescriptor = ::GlobalAlloc(GPTR,
sizeof(FILEGROUPDESCRIPTOR)+(sizeof(TCHAR) * bytesToAllocate) +
(this->m_numberOfItems + sizeof(FILEDESCRIPTOR)));
FILEGROUPDESCRIPTOR*
group=(FILEGROUPDESCRIPTOR*)::GlobalLock(hgDescriptor);
group->cItems=this->m_numberOfItems;
// The problem is likely here:
::CopyMemory(group->fgd, descriptors, (sizeof(TCHAR)
* bytesToAllocate) +
(this->m_numberOfItems + sizeof(FILEDESCRIPTOR)));
// OR something like
//group->fgd=descriptors;
::GlobalUnlock(hgDescriptor);
pMedium->tymed = TYMED_HGLOBAL;
pMedium->hGlobal = hgDescriptor;
pMedium->pUnkForRelease = NULL;
for(int i=0; i<this->m_numberOfItems; i++) delete[]
filesToRequest[i];
delete[]filesToRequest;
return S_OK;
}
I haven't managed to reach the code for CFSTR_FILECONTENTS yet, so any
suggestion on how to manage that situation as well would be appreciated! By
the way, the process which actually retrieves the selected files puts them as
actual files in a temporary directory, so what Explorer should do is just
move them to the 'Paste' target. Should I perform the moving process? Does
anyone have code snippets on how to deal with these formats? I can't get it
from the documentation!
Thank you very much for your help!