Not able to get FileContents after drop on form occured
-
Hello, here is the description of my problem:
I'm dragging the mail from outlook and drop it on my form and all of these methods failed to get the FileContents from the IDataObject which i get when the drop event occured.:
- I've tried c++ framework Qt ver 5.5. to obtain the data and got these results:
It's the formats avaible and the bytes recieved for each format:
"application/x-qt-windows-mime;value="RenPrivateSourceFolder"" 206
"application/x-qt-windows-mime;value="RenPrivateLatestMessages"" 420
"application/x-qt-windows-mime;value="RenPrivateMessages"" 420
"application/x-qt-windows-mime;value="RenPrivateItem"" 0
"application/x-qt-windows-mime;value="FileGroupDescriptor"" 668
"application/x-qt-windows-mime;value="FileGroupDescriptorW"" 1188
"application/x-qt-windows-mime;value="FileNameW"" 0
"application/x-qt-windows-mime;value="FileContents"" 0
"application/x-qt-windows-mime;value="Object Descriptor"" 194
"text/plain" 166
"application/x-qt-windows-mime;value="Csv"" 98as you can see the FileContents format returns zero bytearray.
- Ok,i thought the problem maybe with the qt's implementation of the drag'n'drop operation,so i've implemented the win API approach of implementing the IDropTarget interface, involving registering my window to be able to catch
the drop event. When the drop event occurs, i get the IDataObject which must contain the data being dropped.
But results are the same. I Got the zero bytearray of the FileContents structure. Here is the snippet of my code:
STDMETHODIMP QDropTarget::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState,
POINTL pt, LPDWORD pdwEffect)
{
static UINT cf = RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR);
static FORMATETC fmtetc = { cf, 0, DVASPECT_CONTENT, 0, TYMED_HGLOBAL };
//getting the description of the files being dropped
STGMEDIUM medium;
HRESULT hr = pDataObj->GetData(&fmtetc, &medium);
if (!FAILED(hr))
{
FILEGROUPDESCRIPTOR* files = static_cast<FILEGROUPDESCRIPTOR*>(GlobalLock(medium.hGlobal));
int items_count=files->cItems;
for (int i=0;i<items_count;i++){
QString filename=QString::fromWCharArray(files->fgd[i].cFileName).toUtf8().data();//getting filenames - works as expected
}
static UINT cf = RegisterClipboardFormat(CFSTR_FILECONTENTS);
static FORMATETC fileContentFormat = { cf, NULL, DVASPECT_CONTENT,0, TYMED_HGLOBAL|TYMED_ISTORAGE|TYMED_ISTREAM};
STGMEDIUM medium2;
HRESULT hr2 = pDataObj->GetData(&fileContentFormat, &medium2);
if (!FAILED(hr2))
{
qDebug()<<GlobalSize(medium2.hGlobal);//zero result
qDebug()<<(medium2.pstg==NULL);//zero result
qDebug()<<(medium2.pstm==NULL);//zero result
qDebug()<<"Filecontents extracted";.......
- I loaded the ClipSpy utility, which allow to drop files on it's form and show avaible formats and the size of the structure represented by each format. And again the filecontent size is zero.
Can you tell me is this an outlook problem? Is Outlook really able to pass the message content through the WINAPI approach of drag'n'drop via COM objects?Thanks in advance.
-
hi and welcome
I have never tried to drag directly to other app.
But i have many times dragged messages to a folder and got a
.msg file (s).
That/those seems to have all info
as its possible to later restore mails from the .msg files on
brand new profile.
So would be strange if drop to other app would not contain all info too. -
it seems developers in outlook does not stick to the general approach of drag n drop on Windows described here https://msdn.microsoft.com/en-us/library/windows/desktop/bb776904(v=vs.85).aspx?f=255&MSPPError=-2147217396. I've asked on microsoft forum - (https://social.msdn.microsoft.com/Forums/office/en-US/b2e50357-a87c-4323-a851-5050b0e5b34b/not-able-to-get-filecontents-after-drop-on-form-occured?forum=outlookdev) and the answer from thier developer is :
The MSDN article is a general description of shell data transfer. I have given you the solution that is specific to how Outlook implements drag and drop. -
Ok thank you for reporting back.
Seems outlook is a bit special but that was no surprise :)Did the raw c code then work?
-
it need a few more dependencies, like i need to compile [ MAPI Stub Library],(https://mapistublibrary.codeplex.com/) include in my project, Before that, also i need MAPI headers. Also Visual Studio 2015 not able to compile it, because the project requires VS 2010 build tools. i will give a try and then report back. Hope it gonna work.
-
it need a few more dependencies, like i need to compile [ MAPI Stub Library],(https://mapistublibrary.codeplex.com/) include in my project, Before that, also i need MAPI headers. Also Visual Studio 2015 not able to compile it, because the project requires VS 2010 build tools. i will give a try and then report back. Hope it gonna work.
@Ivan-Netskin
hopefully :)
VS 2010 seems pretty old. -
i've downloaded the VS2013 and compiled the lib succesfully. After that i'm trying to add the library to my project in QtCreator. And it says - LNK1181: cannot open input file 'MapiStubLibrary.lib' . Am i missing something?
-
okay, as the article says:
An alternate method of incorporating the MAPI Stub Library is to copy the source files, MapiStubLibrary.cpp and StubUtils.cpp, directly into your project and remove any linkage to Mapi32.lib and any code that explicitly links to MAPI.this is accomplished, but you may required some libs which is distributed with windows sdks. The library needed for me was advapi32.lib
-
from here you can get the answer. Finally, i've have achieved this.
-
from here you can get the answer. Finally, i've have achieved this.
@Ivan-Netskin
good work :)