Jump to content

_ClipBoard_GetDataEx to array


Recommended Posts

i want to use _ClipBoard_GetDataEx in a loop to retrieve all data from the clipboard and copy it into an array, similar to ?do=embed' frameborder='0' data-embedContent>>_ClipBoard_GetAll by wraithdu, but without the extra memory stuff

Basically all i did was to comment out the memory parts of ?do=embed' frameborder='0' data-embedContent>>_ClipBoard_GetAll, but it doesn't work because the data that gets restored is not the data that was copied into the array

Looking at _ClipBoard_GetDataEx in the help file, i think i am missing the dll stuff...

$tData = DllStructCreate("char Text[8192]", $hMemory)
DllStructGetData($tData, "Text")

The problem is that i don't know how to write the dll functions when the clipboard format (char Text[8192]) could be anything

Here's what i have so far...

#include <Clipboard.au3>
#include <Array.au3>

Global $avClip, $iErr = 0

ConsoleWrite("-------- GET --------" & @LF)
_Clipboard_GetAll($avClip)
If @error Then
    ConsoleWrite("_Clipboard_GetAll error = " & @error & @LF)
    Exit
EndIf
_ArrayDisplay($avClip)
;Exit
Sleep(100)
ConsoleWrite("-------- PUT --------" & @LF)
_ClipBoard_PutAll($avClip)
If @error Then ConsoleWrite("_ClipBoard_PutAll error = " & @error & @LF)

; http://www.autoitscript.com/forum/topic/81267-clipboard-getall-clipboard-putall-clipboard-wait/

Func _Clipboard_GetAll(ByRef $avClip)

    Local $iFormat = 0, $hMem, $hMem_new, $pSource, $pDest, $iSize, $iErr = 0, $iErr2 = 0

    Dim $avClip[1][2]

    If Not _ClipBoard_Open(0) Then Return SetError(-1, 0, 0)
    Do
        $iFormat = _ClipBoard_EnumFormats($iFormat)
        If $iFormat <> 0 Then
            $hMem = _ClipBoard_GetDataEx($iFormat)
            If $hMem = 0 Then
                $iErr += 1
                ContinueLoop
            EndIf
            ReDim $avClip[UBound($avClip) + 1][2]
            $avClip[0][0] += 1
            $avClip[UBound($avClip) - 1][0] = $hMem
            $avClip[UBound($avClip) - 1][1] = $iFormat
        EndIf
    Until $iFormat = 0
    _ClipBoard_Close()

    Local $ErrRet = 0
    If $iErr Then $ErrRet -= 2
    If $ErrRet Then
        Return SetError($ErrRet, $iErr, 0)
    Else
        Return 1
    EndIf
EndFunc

Func _ClipBoard_PutAll(ByRef $avClip)

    Local $iErr = 0

    If Not IsArray($avClip) Or UBound($avClip, 0) <> 2 Or $avClip[0][0] <= 0 Then Return SetError(-1, 0, 0)

    If Not _ClipBoard_Open(0) Then Return SetError(-2, 0, 0)
    If Not _ClipBoard_Empty() Then
        _ClipBoard_Close()
        Return SetError(-3, 0, 0)
    EndIf
    ; seems to work without closing / reopening the clipboard, but MSDN implies we should do this
    ; since a call to EmptyClipboard after opening with a NULL handle sets the owner to NULL,
    ; and SetClipboardData is supposed to fail, so we close and reopen it to be safe
    _ClipBoard_Close()
    If Not _ClipBoard_Open(0) Then Return SetError(-3, 0, 0)
    For $i = 1 To $avClip[0][0]
        If _ClipBoard_SetDataEx($avClip[$i][0], $avClip[$i][1]) = 0 Then $iErr += 1
    Next
    _ClipBoard_Close()
    If $iErr Then
        Return SetError(-4, $iErr, 0)
    Else
        Return 1
    EndIf
EndFunc
Edited by iCode

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...