diff --git a/PInvoke/Shell32/Clipboard.cs b/PInvoke/Shell32/Clipboard.cs index e278781b..b30e7323 100644 --- a/PInvoke/Shell32/Clipboard.cs +++ b/PInvoke/Shell32/Clipboard.cs @@ -588,7 +588,7 @@ namespace Vanara.PInvoke case IEnumerable 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; /// - /// 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 instance is a reference value pulled from - /// the clipboard's HGLOBAL allocation. + /// Gets the file name array appended to a 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 is a valid + /// pointer to a structure. /// /// The file list. - 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(); + 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(); - 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(); + //return h.ToStringEnum(df.fWide ? CharSet.Unicode : CharSet.Ansi, Marshal.SizeOf(typeof(DROPFILES))).ToArray(); } public IntPtr Write(object value) => Write(value, Marshal.SystemDefaultCharSize != 1);