Modify

Opened 5 months ago

Closed 3 months ago

#3982 closed Bug (Works For Me)

_ClipPutFile should not free memory

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.

Attachments (0)

Change History (8)

comment:1 Changed 4 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 4 months ago by mLipok (previous) (diff)

comment:2 Changed 4 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 4 months ago by mLipok

  • Description modified (diff)

comment:4 Changed 4 months ago by Jpm

I understand what you write again
just post a repro script to show where the error can occur
in what I post I don't see any error the _clipget get the right info

comment:5 Changed 3 months ago by Andreik

I don't know what can happen if you release the object owned by the system or specific cases that will cause an error but can we assume that Microsoft knows what they are talking about when they say that the object it's managed by the system? It might work in 99% of cases without any errors and produce an error in some niche cases. I think we should follow MSDN guidance and fix possible errors that might appear in some cases. It's just best practice.

comment:6 Changed 3 months ago by Jpm

Just produce a script that will provide the error with the current implementation.
for me the Clipget does not produce any error even if the the GlobalFree is executed before the CloseClipboard

comment:7 Changed 3 months ago by Nine

There is not a systematic error when freeing the memory. It is a recommandation of MSDN. I think it should be enough.

comment:8 Changed 3 months ago by Jpm

  • Resolution set to Works For Me
  • Status changed from assigned to closed

Sorry I will close and except another Ticket with a script repro

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.