//!!!! we have heap corruption with this method despite the fact that everything looks right. public static bool SetFileDropPaths( List<string> lstPaths, bool fCut, IntPtr hwnd = default ) { string str = MakeFILEOPPATHS( lstPaths ); if( /*( hwnd != IntPtr.Zero ) &&*/ ( str.Length > 1 ) ) { if( !PI.OpenClipboard( hwnd ) ) { return false; } PI.EmptyClipboard(); try { PI.DROPFILES structure = new PI.DROPFILES(); structure.pFiles = Marshal.SizeOf( structure ); structure.fWide = true; int size = Marshal.SizeOf( structure ) + ( str.Length * Marshal.SystemMaxDBCSCharSize ); IntPtr hMem = PI.GlobalAlloc( 0x42, (IntPtr)size ); if( hMem != IntPtr.Zero ) { IntPtr ptr = PI.GlobalLock( hMem ); Marshal.StructureToPtr( structure, ptr, false ); Marshal.Copy( str.ToCharArray(), 0, PtrPlus( ptr, Marshal.SizeOf( structure ) ), str.Length ); PI.GlobalUnlock( hMem ); } IntPtr ptr3 = PI.GlobalAlloc( 0x42, (IntPtr)4 ); if( ptr3 != IntPtr.Zero ) { IntPtr destination = PI.GlobalLock( ptr3 ); byte[] source = new byte[ 4 ]; source[ 0 ] = fCut ? ( (byte)2 ) : ( (byte)5 ); Marshal.Copy( source, 0, destination, 4 ); PI.GlobalUnlock( ptr3 ); } if( ( hMem != IntPtr.Zero ) && ( ptr3 != IntPtr.Zero ) ) { uint uFormat = PI.RegisterClipboardFormat( "Preferred DropEffect" ); PI.SetClipboardData( PI.CF_HDROP, hMem ); PI.SetClipboardData( uFormat, ptr3 ); return true; } } finally { PI.CloseClipboard(); } } return false; }