Fixed IDataObject.SetData extension to get CF_HDROP right with Unicode and changed DROPFILES.DangerousGetFileList to static function taking a DROPFILES pointer.

pull/395/head
David Hall 2023-05-01 16:39:54 -06:00
parent 275016379a
commit 34ce9eeaec
1 changed files with 12 additions and 10 deletions

View File

@ -588,7 +588,7 @@ namespace Vanara.PInvoke
case IEnumerable<string> strlist:
// Handle HDROP specifically since its formatter cannot be specified.
if (CLIPFORMAT.CF_HDROP.Equals(formatId))
mbr = new ClipboardHDROPFormatter().Write(strlist, charSet != CharSet.Ansi);
mbr = new ClipboardHDROPFormatter().Write(strlist, charSet == CharSet.Unicode || (charSet == CharSet.Auto && Marshal.SystemDefaultCharSize == 2));
else
mbr = strlist.MarshalToPtr(StringListPackMethod.Concatenated, MoveableHGlobalMemoryMethods.Instance.AllocMem, out _, charSet, 0,
MoveableHGlobalMemoryMethods.Instance.LockMem, MoveableHGlobalMemoryMethods.Instance.UnlockMem);
@ -884,15 +884,16 @@ namespace Vanara.PInvoke
public bool fWide;
/// <summary>
/// Gets the file name array appended to this struture. It consists of a series of strings, each containing one file's fully
/// qualified path. This method should only be called when the <see cref="DROPFILES"/> instance is a reference value pulled from
/// the clipboard's HGLOBAL allocation.
/// Gets the file name array appended to a <see cref="DROPFILES"/> struture in memory. It consists of a series of strings, each
/// containing one file's fully qualified path. This method should only be called when <paramref name="pDropFiles"/> is a valid
/// pointer to a <see cref="DROPFILES"/> structure.
/// </summary>
/// <returns>The file list.</returns>
public string[] DangerousGetFileList()
public static string[] DangerousGetFileList(IntPtr pDropFiles)
{
using PinnedObject pinned = new(this);
return ((IntPtr)pinned).ToStringEnum(fWide ? CharSet.Unicode : CharSet.Ansi, (int)pFiles).ToArray();
SafeMoveableHGlobalHandle h = new(pDropFiles, false);
DROPFILES df = h.ToStructure<DROPFILES>();
return h.ToStringEnum(df.fWide ? CharSet.Unicode : CharSet.Ansi, (int)df.pFiles).ToArray();
}
}
@ -1820,9 +1821,10 @@ namespace Vanara.PInvoke
{
public object Read(IntPtr hGlobal)
{
SafeMoveableHGlobalHandle h = new(hGlobal, false);
DROPFILES df = h.ToStructure<DROPFILES>();
return h.ToStringEnum(df.fWide ? CharSet.Unicode : CharSet.Ansi, Marshal.SizeOf(typeof(DROPFILES))).ToArray();
return DROPFILES.DangerousGetFileList(hGlobal);
//SafeMoveableHGlobalHandle h = new(hGlobal, false);
//DROPFILES df = h.ToStructure<DROPFILES>();
//return h.ToStringEnum(df.fWide ? CharSet.Unicode : CharSet.Ansi, Marshal.SizeOf(typeof(DROPFILES))).ToArray();
}
public IntPtr Write(object value) => Write(value, Marshal.SystemDefaultCharSize != 1);