| 90 | } |
| 91 | |
| 92 | std::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 | } |
no test coverage detected