#3982 closed Bug

_ClipPutFile should not free memory — at Version 3

Reported by: Nine Owned by: J-Paul Mesnage
Milestone: Component: AutoIt
Version: 3.3.16.1 Severity: None
Keywords: Cc:

Description (last modified by mLipok)

As per discussion here and MSDN :

https://www.autoitscript.com/forum/topic/211212-how-to-copy-a-file-to-the-clipboard-for-pasting-in-explorer/#comment-1527751

                        $aCall = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hGlobal)
                        If (@error Or $aCall[0]) And Not $iError Then
                                $iError = @error + 90
                                $iLastError = _WinAPI_GetLastError()
                        EndIf

should be removed from the script.

Change History (3)

comment:1 by J-Paul Mesnage, on Jan 4, 2024 at 4:52:43 PM

Owner: set to J-Paul Mesnage
Status: newassigned

Hi,
I don't see any reason to change the UDF
The following script work fine

#include <Memory.au3>
#include <Misc.au3>
#include <Clipboard.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIConv.au3>

Local $sFilePath = '<path to your file>|other file'
_ClipPutFile($sFilePath)
MsgBox($MB_SYSTEMMODAL, "_ClipPutFile()", "Content of Clipboard:" & @CRLF & ClipGet())

Last edited on Jan 5, 2024 at 3:06:48 AM by mLipok (previous) (diff)

comment:2 by anonymous, on Jan 4, 2024 at 9:04:20 PM

The function _ClipPutFile() uses SetClipboardData. MSDN state that if SetClipboardData succeeds, the system owns the object identified by the hMem parameter. The application may not write to or free the data once ownership has been transferred to the system, but it can lock and read from the data until the CloseClipboard function is called.

comment:3 by mLipok, on Jan 5, 2024 at 3:06:32 AM

Description: modified (diff)
Note: See TracTickets for help on using tickets.