-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutlookDataObject.cpp
More file actions
99 lines (82 loc) · 3.2 KB
/
OutlookDataObject.cpp
File metadata and controls
99 lines (82 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "OutlookDataObject.h"
#include "qdnd_p.h"
#include <QWindowsMime>
#include <QMimeData>
#include <Shlobj.h>
#include <ObjIdl.h>
OutlookDataObject::OutlookDataObject(const QMimeData* data)
: m_data(data)
{
}
OutlookDataObject::~OutlookDataObject(void)
{
}
bool OutlookDataObject::isValid() const
{
return m_data && m_data->hasFormat("FileGroupDescriptorW");
}
QStringList OutlookDataObject::filenames() const
{
QStringList returnValue;
if (m_data)
{
QByteArray fileGroupDescriptorBytes = m_data->data("FileGroupDescriptorW");
FILEGROUPDESCRIPTORW* fileDescriptor = (FILEGROUPDESCRIPTORW*) fileGroupDescriptorBytes.data();
for (int i = 0; i < fileDescriptor->cItems; ++i)
{
returnValue << QString::fromWCharArray(fileDescriptor->fgd[i].cFileName);
}
}
return returnValue;
}
QByteArray OutlookDataObject::fileContent(const QString& filename) const
{
QByteArray returnValue;
if (const QDropData* dropData = dynamic_cast<const QDropData*>(m_data))
{
int indexOfStream = filenames().indexOf(filename);
if (indexOfStream >= 0)
{
FORMATETC formatetc;
formatetc.cfFormat = 49325;
formatetc.ptd = 0;
formatetc.dwAspect = 1;
formatetc.lindex = 0;
formatetc.tymed = 12;
STGMEDIUM medium = {0};
if (dropData->currentDataObject->GetData(&formatetc, &medium) == S_OK)
{
if (medium.tymed == TYMED_ISTREAM)
{
STATSTG iStreamStat = {0};
medium.pstm->Stat(&iStreamStat, 0);
returnValue.resize(static_cast<int>(iStreamStat.cbSize.QuadPart));
ULONG pcbRead = 0;
medium.pstm->Read((void*) returnValue.constData(), returnValue.size(), &pcbRead);
}
else if (medium.tymed == TYMED_ISTORAGE)
{
//create a ILockBytes (unmanaged byte array) and then create a IStorage using the byte array as a backing store
ILockBytes* iLockBytes = 0;
HRESULT res = CreateILockBytesOnHGlobal(0, true, &iLockBytes);
IStorage* iStorage = 0;
res = StgCreateDocfileOnILockBytes(iLockBytes, 0x00001012, 0, &iStorage);
//copy the returned IStorage into the new IStorage
medium.pstg->CopyTo(0, 0, 0, iStorage);
iLockBytes->Flush();
iStorage->Commit(0);
//get the STATSTG of the ILockBytes to determine how many bytes were written to it
STATSTG iLockBytesStat = {0};
iLockBytes->Stat(&iLockBytesStat, 1);
returnValue.resize(iLockBytesStat.cbSize.QuadPart);
ULARGE_INTEGER offset;
offset.QuadPart = 0;
iLockBytes->ReadAt(offset, (void*) returnValue.constData(), returnValue.size(), 0);
iStorage->Release();
iLockBytes->Release();
}
}
}
}
return returnValue;
}