Jump to content

bugfix: hard crash when using _ClipBoard_GetData


Recommended Posts

This one's been around a while, and I think maybe I've fixed it. Or something. I'm sure this will help someone, since I've seen this problem go unanswered in the archived bug report forum!

I found this proposed change by looking at examples given for the Clipboard API in other programming languages, and the one *difference* that they all had in common was to lock and copy the memory when reading from the clipboard.

CODE
Func _ClipBoard_GetData_Carefully($iFormat = 1)

Local $hMemory, $tData

Local $hMemoryDest, $hLock

If Not _ClipBoard_IsFormatAvailable($iFormat) Then Return SetError(-1, 0, 0)

If Not _ClipBoard_Open(0) Then Return SetError(-2, 0, 0)

$hMemory = _ClipBoard_GetDataEx($iFormat)

_ClipBoard_Close()

If $hMemory = 0 Then Return SetError(-3, 0, 0)

Switch $iFormat

Case $CF_TEXT, $CF_OEMTEXT

;THIS WAS BAD: $tData = DllStructCreate("char Text[8192]", $hMemory)

$tData = DllStructCreate("char Text[8192]") ; do it this way so it is allocated...?

$hMemoryDest = DllStructGetPtr($tData)

; so let's lock that clipboard memory down and make our own for-sure copy.

$hLock = _MemGlobalLock($hMemory)

If $hLock = 0 Then Return SetError(-4, 0, 0)

; OK, $hLock should now be the pointer into the clipboard memory

_MemMoveMemory($hLock, $hMemoryDest, 8192)

_MemGlobalUnlock($hMemory)

; OK *now* we should have our own, good copy.

Return DllStructGetData($tData, "Text")

Case $CF_UNICODETEXT

Return _WinAPI_WideCharToMultiByte($tData)

Case Else

Return $hMemory

EndSwitch

EndFunc ;==>_ClipBoard_GetData_Carefully

Cheers,

Trip

Link to comment
Share on other sites

This one's been around a while, and I think maybe I've fixed it. Or something. I'm sure this will help someone, since I've seen this problem go unanswered in the archived bug report forum!

The old Bug Report forum only exists as an historical archive. Did you look for this issue in the Bug Trac that is now actively used?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The old Bug Report forum only exists as an historical archive. Did you look for this issue in the Bug Trac that is now actively used?

:)

I looked, but didn't see any way to get past the login page.

At least this way my post takes its place in Google next to all the poor saps who got told it was probably their own fault when honestly I think it wasn't.

:(

Trip

Link to comment
Share on other sites

The old Bug Report forum only exists as an historical archive. Did you look for this issue in the Bug Trac that is now actively used?

:)

Thanks, I have submitted this as a bug/bugfix.

I wish I could figure out just *why* I find Trac so impenetrable. I really *want* to like it, but there's something about it that just sits there, not looking like one could actually *do* anything with it. Maybe it's something that some shiny chrome could fix. *shrug*

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...