MCPcopy Create free account
hub / github.com/derceg/explorerplusplus / ExtractDroppedFilesList

Function ExtractDroppedFilesList

Explorer++/Helper/DataExchangeHelper.cpp:92–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92std::vector<std::wstring> ExtractDroppedFilesList(IDataObject *dataObject)
93{
94 FORMATETC droppedFilesFormatEtc = GetDroppedFilesFormatEtc();
95 wil::unique_stg_medium stgMedium;
96 HRESULT hr = dataObject->GetData(&droppedFilesFormatEtc, &stgMedium);
97
98 if (hr != S_OK)
99 {
100 return {};
101 }
102
103 wil::unique_hglobal_locked mem(stgMedium.hGlobal);
104
105 if (!mem)
106 {
107 return {};
108 }
109
110 auto *dropFiles = static_cast<DROPFILES *>(mem.get());
111 UINT numDroppedFiles =
112 DragQueryFile(reinterpret_cast<HDROP>(dropFiles), 0xFFFFFFFF, nullptr, 0);
113 std::vector<std::wstring> droppedFiles;
114
115 for (UINT i = 0; i < numDroppedFiles; i++)
116 {
117 UINT numCharacters = DragQueryFile(reinterpret_cast<HDROP>(dropFiles), i, nullptr, 0);
118
119 if (numCharacters == 0)
120 {
121 continue;
122 }
123
124 std::wstring fullFileName;
125 fullFileName.resize(numCharacters + 1);
126
127 UINT charactersCopied = DragQueryFile(reinterpret_cast<HDROP>(dropFiles), i,
128 fullFileName.data(), static_cast<UINT>(fullFileName.capacity()));
129
130 if (charactersCopied == 0)
131 {
132 continue;
133 }
134
135 droppedFiles.push_back(fullFileName);
136 }
137
138 return droppedFiles;
139}

Callers 1

Calls 5

GetDroppedFilesFormatEtcFunction · 0.85
GetDataMethod · 0.80
resizeMethod · 0.80
getMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected