I might be dense, but I can't get this working. Anyone know how to copy TextToCopy to the ClipBoard?


hClipData DWORD ?
TextToCopy DB "this is the text...",0
...
Invoke OpenClipboard,hWnd
Invoke EmptyClipboard
Invoke GlobalAlloc,GMEM_MOVEABLE + GMEM_ZEROINIT,38
Mov hClipData,eax
Invoke GlobalLock,hClipData
Mov eax,OFFSET TextToCopy
Invoke SetClipboardData,CF_TEXT,hClipData
Invoke GlobalUnlock,hClipData
Invoke CloseClipboard
Posted on 2005-10-25 10:04:05 by EvilElvis
You don't copy the Text into the Buffer. Replace your mov eax, offset TextToCopy with an invoke lstrcpy, hClipData, offset TextToCopy.
Posted on 2005-10-25 10:45:45 by JimmyClif
JimmyClif is wright. Also I believe memory must not be locked.Try something like this:

    invoke lstrlen, addr szText
    invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT or GMEM_SHARE, eax
    mov hClipData, eax    ; not forget checking errors
    invoke lstrcpy, hClipData, addr szText
    invoke OpenClipboard, hwnd
    .if( !eax )
        ; error opening clipboard so we must free memory
        invoke GlobalFree, hClipData
        jmp skip_job
    .endif
    invoke EmptyClipboard
    invoke SetClipboardData, CF_TEXT, hClipData
    invoke CloseClipboard
skip_job:
  ....


I didn't test it, but I think it will work. Hope it helps.

Regards.

Kecol.-
Posted on 2005-10-25 10:59:41 by Kecol

; Kecol
invoke lstrlen, addr szText
inc eax

dont forget the 0 byte ;)
Posted on 2005-10-25 20:07:27 by drizz
Hey drizz, I wrote the code in 'Post reply' text area (on the flight). You are wright with your correction, it is just I pressed 'Spell Check' button and the process threw no compiling errors, so I decided to post the code (do not trust in 'Spell Check' anymore). I'm just kidding :). Of course I know this code will compile with no errors (I must stop smoking).
Posted on 2005-10-25 21:16:37 by Kecol
Thanks for the help guys.

Now I have this, still nothing in the clipboard though. I'm trying to copy a GUID to the clipboard.


GUIDTextBufferA db 38 dup(?)
...
Invoke lstrlen, ADDR GUIDTextBufferA
Inc eax
Invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT or GMEM_SHARE, eax
Mov hClipData, eax   
Invoke lstrcpy, hClipData, ADDR GUIDTextBufferA
Invoke OpenClipboard, hWnd
.If( !eax )
    Invoke GlobalFree, hClipData
    Jmp skip_job
.Endif
Invoke EmptyClipboard
Invoke SetClipboardData, CF_TEXT, hClipData
Invoke CloseClipboard
Invoke GlobalFree, hClipData
skip_job:
Posted on 2005-10-26 04:21:30 by EvilElvis
There you go:


Invoke OpenClipboard,hWnd
Invoke EmptyClipboard
Invoke GlobalAlloc,GMEM_MOVEABLE + GMEM_ZEROINIT,38
Mov hClipData,eax
Invoke GlobalLock,hClipData
invoke lstrcpy,eax,offset TextToCopy
Invoke SetClipboardData,CF_TEXT,hClipData
Invoke GlobalUnlock,hClipData
Invoke CloseClipboard


Tried & worked.
Posted on 2005-10-26 05:55:04 by JimmyClif
Ah, yeah, now I see what I did wrong. Thanks alot for the help guys!
Posted on 2005-10-26 06:03:58 by EvilElvis