windows: Support dropping targets with filenames longer than 260 characters (#9115)

use `Vec` instead of slice to support dynamic filename length.

Release Notes:
- N/A
This commit is contained in:
张小白 2024-03-13 12:19:31 +08:00 committed by GitHub
parent fb83cf2042
commit 9a2dceeea1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,7 +22,7 @@ use smallvec::SmallVec;
use windows::{
core::{implement, w, HSTRING, PCWSTR},
Win32::{
Foundation::{FALSE, HINSTANCE, HWND, LPARAM, LRESULT, MAX_PATH, POINTL, S_OK, WPARAM},
Foundation::{FALSE, HINSTANCE, HWND, LPARAM, LRESULT, POINTL, S_OK, WPARAM},
Graphics::Gdi::{BeginPaint, EndPaint, InvalidateRect, PAINTSTRUCT},
System::{
Com::{IDataObject, DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL},
@ -983,9 +983,9 @@ impl IDropTarget_Impl for WindowsDragDropHandler {
let hdrop = idata.u.hGlobal.0 as *mut HDROP;
let file_count = DragQueryFileW(*hdrop, DRAGDROP_GET_FILES_COUNT, None);
for file_index in 0..file_count {
let mut buffer = [0u16; MAX_PATH as _];
let filename_length = DragQueryFileW(*hdrop, file_index, None) as usize;
let ret = DragQueryFileW(*hdrop, file_index, Some(&mut buffer));
let mut buffer = vec![0u16; filename_length + 1];
let ret = DragQueryFileW(*hdrop, file_index, Some(buffer.as_mut_slice()));
if ret == 0 {
log::error!("unable to read file name");
continue;