diff --git a/src/xenia/app/emulator_window.cc b/src/xenia/app/emulator_window.cc index 08240fb7f..a676302f1 100644 --- a/src/xenia/app/emulator_window.cc +++ b/src/xenia/app/emulator_window.cc @@ -291,9 +291,8 @@ bool EmulatorWindow::Initialize() { return true; } -void EmulatorWindow::FileDrop(wchar_t* filename) { - std::wstring path = filename; - auto result = emulator_->LaunchPath(path); +void EmulatorWindow::FileDrop(const wchar_t* filename) { + auto result = emulator_->LaunchPath(filename); if (XFAILED(result)) { // TODO: Display a message box. XELOGE("Failed to launch target: %.8X", result); diff --git a/src/xenia/app/emulator_window.h b/src/xenia/app/emulator_window.h index 40a06d5fd..3afb1e631 100644 --- a/src/xenia/app/emulator_window.h +++ b/src/xenia/app/emulator_window.h @@ -43,7 +43,7 @@ class EmulatorWindow { bool Initialize(); - void FileDrop(wchar_t* filename); + void FileDrop(const wchar_t* filename); void FileOpen(); void FileClose(); void ShowContentDirectory(); diff --git a/src/xenia/ui/ui_event.h b/src/xenia/ui/ui_event.h index 517ba1e2a..db494a1c6 100644 --- a/src/xenia/ui/ui_event.h +++ b/src/xenia/ui/ui_event.h @@ -28,14 +28,14 @@ class UIEvent { class FileDropEvent : public UIEvent { public: - FileDropEvent(Window* target, wchar_t* filename) + FileDropEvent(Window* target, const wchar_t* filename) : UIEvent(target), filename_(filename) {} ~FileDropEvent() override = default; - wchar_t* filename() const { return filename_; } + const wchar_t* filename() const { return filename_; } private: - wchar_t* filename_ = nullptr; + const wchar_t* filename_ = nullptr; }; class KeyEvent : public UIEvent { diff --git a/src/xenia/ui/window_win.cc b/src/xenia/ui/window_win.cc index f1016a65e..2912ec4a0 100644 --- a/src/xenia/ui/window_win.cc +++ b/src/xenia/ui/window_win.cc @@ -492,16 +492,19 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, switch (message) { case WM_DROPFILES: { - TCHAR lpszFile[MAX_PATH] = {0}; - UINT uFiles = 0; - HDROP hDrop = (HDROP)wParam; - // Get number of files dropped - uFiles = DragQueryFile(hDrop, -1, NULL, NULL); + HDROP hDrop = reinterpret_cast(wParam); + std::wstring path; - // Only getting first file dropped (other files ignored) - if (DragQueryFile(hDrop, 0, lpszFile, MAX_PATH)) { - auto e = FileDropEvent(this, lpszFile); - OnFileDrop(&e); + // Get required buffer size + UINT buf_size = DragQueryFileW(hDrop, 0, nullptr, 0); + if (buf_size > 0) { + path.resize(buf_size + 1); // Give space for a null terminator + + // Only getting first file dropped (other files ignored) + if (DragQueryFileW(hDrop, 0, &path[0], buf_size + 1)) { + auto e = FileDropEvent(this, path.c_str()); + OnFileDrop(&e); + } } DragFinish(hDrop);