I think it's wrong to free the Mem, as it will be handled by the OS.
Here's a snippet I use in SMF.
#include <ClipBoard.au3>
#include <WinAPISysWin.au3>
Global Const $DROPFILES = "DWORD pFiles; int pt[2]; int fNC; int fWide;"
Global Const $CFSTR_PREFERREDDROPEFFECT = "Preferred DropEffect"
Global Const $CF_PREFERREDDROPEFFECT = _ClipBoard_RegisterFormat($CFSTR_PREFERREDDROPEFFECT)
Global Const $DROPEFFECT_COPY = 1
Global Const $DROPEFFECT_MOVE = 2
_Clipboard_Copy_File(@ScriptFullPath)
; _Clipboard_Move_File(@ScriptFullPath)
Func _Clipboard_Copy_File($sFile)
Local $hClip = _ClipBoard_Open(_WinAPI_GetDesktopWindow())
If $hClip Then
_ClipBoard_Empty()
Local $HDROP = _CreateDROPFILES($sFile) ; Mem must NOT be freed via_MemGlobalFree(), as script will crash or fail. Mem will be handled by OS.
Local $DROPEFFECT = _CreatePREFERREDDROPEFFECT($DROPEFFECT_COPY) ; Mem must NOT be freed via_MemGlobalFree(), as script will crash or fail. Mem will be handled by OS.
_ClipBoard_SetDataEx($HDROP, $CF_HDROP)
_ClipBoard_SetDataEx($DROPEFFECT, $CF_PREFERREDDROPEFFECT)
_ClipBoard_Close()
EndIf
EndFunc ;==>_Clipboard_Copy_File
Func _Clipboard_Move_File($sFile)
Local $hClip = _ClipBoard_Open(_WinAPI_GetDesktopWindow())
If $hClip Then
_ClipBoard_Empty()
Local $HDROP = _CreateDROPFILES($sFile) ; Mem must NOT be freed via_MemGlobalFree(), as script will crash or fail. Mem will be handled by OS.
Local $DROPEFFECT = _CreatePREFERREDDROPEFFECT($DROPEFFECT_MOVE) ; Mem must NOT be freed via_MemGlobalFree(), as script will crash or fail. Mem will be handled by OS.
_ClipBoard_SetDataEx($HDROP, $CF_HDROP)
_ClipBoard_SetDataEx($DROPEFFECT, $CF_PREFERREDDROPEFFECT)
_ClipBoard_Close()
EndIf
EndFunc ;==>_Clipboard_Move_File
;===============================================================================
;
; Function Name: _CreateDROPFILES
; Description:: Creates a DROPFILES-structure
; Parameter(s): $Files - Pipe-separated list of files to copy: example: C:\File1.bin|D:\AnotherFile.dat
; Requirement(s): COM/OLE UDF
; Return Value(s): HGLOBAL-Pointer to a DROPFILES structure
; Author(s): prog@ndy
;
;===============================================================================
; http://www.autoitscript.com/forum/index.php?showtopic=91046&view=findpost&p=654849
; http://www.autoit.de/index.php?page=Thread&postID=81909&highlight=hdrop#post81909
Func _CreateDROPFILES($Files)
$Files = String($Files)
Local $hMem = _MemGlobalAlloc(_DragDrop_SIZEOF($DROPFILES) + ((StringLen($Files) + 2) * 2), $GPTR)
$Files = StringSplit($Files, "|")
Local $stDROPFILES = DllStructCreate($DROPFILES, $hMem)
Local $hPtr = $hMem + DllStructGetSize($stDROPFILES)
DllStructSetData($stDROPFILES, "fWide", 1)
DllStructSetData($stDROPFILES, 1, DllStructGetSize($stDROPFILES))
For $i = 1 To $Files[0]
$next = DllStructCreate("wchar[" & StringLen($Files[$i]) + 1 & "]", $hPtr)
DllStructSetData($next, 1, $Files[$i] & ChrW(0))
$hPtr += (StringLen($Files[$i]) + 1) * 2
Next
Local $next = DllStructCreate("wchar[1]", $hPtr)
DllStructSetData($next, 1, ChrW(0))
Return $hMem
EndFunc ;==>_CreateDROPFILES
; Prog@ndy
Func _CreatePREFERREDDROPEFFECT($dwEffect)
Local $pMem = _MemGlobalAlloc(4, $GPTR) ; 4 bytes - 1 DWORD
If Not $pMem Then Return SetError(1, 0, 0)
DllStructSetData(DllStructCreate("DWORD", $pMem), 1, $dwEffect)
Return $pMem
EndFunc ;==>_CreatePREFERREDDROPEFFECT
; Author: Prog@ndy
Func _DragDrop_SIZEOF($tagStruct)
Return DllStructGetSize(DllStructCreate($tagStruct, 1))
EndFunc ;==>_DragDrop_SIZEOF