|
34 | 34 | #include <ctime>
|
35 | 35 | #include <bitset>
|
36 | 36 | #include <list>
|
| 37 | +#include <vector> |
37 | 38 |
|
38 | 39 | #undef DELETE
|
39 | 40 |
|
@@ -712,23 +713,29 @@ bool handleMsg(UINT msg, WPARAM wp, LPARAM lp, LRESULT& result)
|
712 | 713 | {
|
713 | 714 | POINT pos;
|
714 | 715 | DragQueryPoint((HDROP)wp, &pos);
|
715 |
| - // Passing 0xFFFFFFFF will return the file count. |
716 |
| - int numFiles = (int)DragQueryFileW((HDROP)wp, 0xFFFFFFFF, 0, 0); |
717 |
| - char** files = (char**)malloc(sizeof(char*) * numFiles); |
718 |
| - for(int i = 0; i < numFiles; ++i) |
| 716 | + |
| 717 | + // Get the number of files dropped. |
| 718 | + UINT numFiles = DragQueryFileW((HDROP)wp, 0xFFFFFFFF, nullptr, 0); |
| 719 | + std::vector<String> files(numFiles); |
| 720 | + |
| 721 | + for (UINT i = 0; i < numFiles; ++i) |
719 | 722 | {
|
720 |
| - // Giving 0 for the stringbuffer returns path size without nullbyte. |
721 |
| - int pathlen = (int)DragQueryFileW((HDROP)wp, i, 0, 0); |
722 |
| - WideString wstr(pathlen, 0); |
723 |
| - DragQueryFileW((HDROP)wp, i, wstr.begin(), pathlen + 1); |
724 |
| - String str = Narrow(wstr); |
725 |
| - files[i] = (char*)malloc(str.len() + 1); |
726 |
| - memcpy(files[i], str.begin(), str.len() + 1); |
| 723 | + // Get the length of the file path and retrieve it. |
| 724 | + UINT pathLen = DragQueryFileW((HDROP)wp, i, nullptr, 0); |
| 725 | + WideString wstr(pathLen, 0); |
| 726 | + DragQueryFileW((HDROP)wp, i, wstr.begin(), pathLen + 1); |
| 727 | + files[i] = Narrow(wstr); |
727 | 728 | }
|
| 729 | + |
728 | 730 | DragFinish((HDROP)wp);
|
729 |
| - myEvents.addFileDrop(files, numFiles, pos.x, pos.y); |
730 |
| - for(int i = 0; i < numFiles; ++i) free(files[i]); |
731 |
| - free(files); |
| 731 | + |
| 732 | + // Pass the file drop event to the input handler. |
| 733 | + std::vector<const char*> filePtrs; |
| 734 | + for (const auto& file : files) |
| 735 | + { |
| 736 | + filePtrs.push_back(file.str()); |
| 737 | + } |
| 738 | + myEvents.addFileDrop(filePtrs.data(), static_cast<int>(filePtrs.size()), pos.x, pos.y); |
732 | 739 | }
|
733 | 740 | break;
|
734 | 741 | }
|
|
0 commit comments