Support Unicode names correctly.

This commit is contained in:
Ottermandias 2023-08-27 14:46:44 +02:00
parent 1ab198af8b
commit f7c2ab5283
2 changed files with 4 additions and 4 deletions

View file

@ -101,7 +101,7 @@ internal partial class DragDropManager
public static extern int RevokeDragDrop(nint hwnd); public static extern int RevokeDragDrop(nint hwnd);
[DllImport("shell32.dll")] [DllImport("shell32.dll")]
public static extern int DragQueryFile(IntPtr hDrop, uint iFile, StringBuilder lpszFile, int cch); public static extern int DragQueryFileW(IntPtr hDrop, uint iFile, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszFile, int cch);
} }
} }
#pragma warning restore SA1600 // Elements should be documented #pragma warning restore SA1600 // Elements should be documented

View file

@ -204,7 +204,7 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
try try
{ {
data.GetData(ref this.formatEtc, out var stgMedium); data.GetData(ref this.formatEtc, out var stgMedium);
var numFiles = DragDropInterop.DragQueryFile(stgMedium.unionmember, uint.MaxValue, new StringBuilder(), 0); var numFiles = DragDropInterop.DragQueryFileW(stgMedium.unionmember, uint.MaxValue, new StringBuilder(), 0);
var files = new string[numFiles]; var files = new string[numFiles];
var sb = new StringBuilder(1024); var sb = new StringBuilder(1024);
var directoryCount = 0; var directoryCount = 0;
@ -212,11 +212,11 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
for (var i = 0u; i < numFiles; ++i) for (var i = 0u; i < numFiles; ++i)
{ {
sb.Clear(); sb.Clear();
var ret = DragDropInterop.DragQueryFile(stgMedium.unionmember, i, sb, sb.Capacity); var ret = DragDropInterop.DragQueryFileW(stgMedium.unionmember, i, sb, sb.Capacity);
if (ret >= sb.Capacity) if (ret >= sb.Capacity)
{ {
sb.Capacity = ret + 1; sb.Capacity = ret + 1;
ret = DragDropInterop.DragQueryFile(stgMedium.unionmember, i, sb, sb.Capacity); ret = DragDropInterop.DragQueryFileW(stgMedium.unionmember, i, sb, sb.Capacity);
} }
if (ret > 0 && ret < sb.Capacity) if (ret > 0 && ret < sb.Capacity)