Opened 12 months ago

Last modified 10 months ago

#3982 closed Bug

_ClipPutFile should not free memory — at Version 3

Reported by: Nine Owned by: Jpm
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 Changed 11 months ago by Jpm

  • Owner set to Jpm
  • Status changed from new to assigned

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 11 months ago by mLipok (previous) (diff)

comment:2 Changed 11 months ago by anonymous

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 Changed 11 months ago by mLipok

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