Hi,
I want ot write a proc to get text in the clipboard, but we don't know what's in there (bytes length) and I can't figure how to get a pointer to it.
This is what I have but I can't go further without your help.
GetClipboardText proc lpszText:dword
local hMemObj:dword
local dwMemLen:dword
local hMemPtr:dword
invoke IsClipboardFormatAvailable, CF_TEXT
.if (eax)
invoke OpenClipboard, NULL
.if (eax)
invoke GetClipboardData, CF_TEXT
.if (eax)
mov hMemObj, eax
invoke GlobalSize, hMemObj
.if (eax)
mov dwMemLen, eax
invoke GlobalLock, hMemObj
.if (eax)
mov hMemPtr, eax
invoke RtlMoveMemory, lpszText, hMemPtr, dwMemLen
invoke GlobalUnlock, hMemObj
invoke GetClipboardText, lpszText
.endif
.endif
.endif
invoke CloseClipboard
.endif
.endif
ret
GetClipboardText endp
:'(
Quick and dirty:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
hglb dd 0
str1 db "my other brother darryl",0
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;------------------------------
; Place str1 on the clipboard.
;------------------------------
invoke OpenClipboard,NULL
.IF (eax)
invoke EmptyClipboard
invoke GlobalAlloc,GMEM_MOVEABLE,SIZEOF str1
.IF (eax)
mov hglb, eax
invoke GlobalLock,hglb
;---------------------
; Pointer now in eax.
;---------------------
invoke MemCopy,ADDR str1,eax,SIZEOF str1
invoke GlobalUnlock,hglb
invoke SetClipboardData,CF_TEXT,hglb
;--------------------------------------------
; System now owns object identified by hglb.
;--------------------------------------------
.IF (eax == 0)
print "SetClipboardData failed",13,10
.ENDIF
.ELSE
print "GlobalAlloc failed",13,10
.ENDIF
invoke CloseClipboard
.ELSE
print "OpenClipboard failed",13,10
.ENDIF
;-------------------------------------
; Get and display the clipboard data.
;-------------------------------------
invoke IsClipboardFormatAvailable,CF_TEXT
.IF (eax)
invoke OpenClipboard,NULL
.IF (eax)
invoke GetClipboardData,CF_TEXT
;----------------------------------------
; Handle to clipboard object now in eax.
;----------------------------------------
.IF (eax)
mov hglb, eax
;------------------------------------------------
; Get and display size of clipboard object (this
; method should work for any clipboard object).
;------------------------------------------------
print ustr$(SIZEOF str1)," bytes",13,10
invoke GlobalSize,hglb
print ustr$(eax)," bytes",13,10
invoke GlobalLock,hglb
;---------------------------------------
; Pointer to clipboard data now in eax.
;---------------------------------------
print eax,13,10,13,10
invoke GlobalUnlock,hglb
.ELSE
print "GetClipboardData failed",13,10
.ENDIF
invoke CloseClipboard
.ELSE
print "OpenClipboard failed",13,10
.ENDIF
.ELSE
print "IsClipboardFormatAvailable failed",13,10
.ENDIF
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
@MichaelW
Thanks a lot :toothy