In the Masmlib.chm help file shows "GetClipboardText" as a function.
I have the m32v9r.zip and it is not there.
Can someone tell me how to get this function, or maybe
a new m32lib file update.
Thanks
hi
try this
GetClipboardText proc lpszBuffer: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
.endif
.endif
.endif
invoke CloseClipboard
.endif
.endif
ret
GetClipboardText endp
greets
ragdog
xroot,
Here are the two masm32 library modules.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.486 ; maximum processor model
.model flat, stdcall ; memory model & calling convention
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\macros\macros.asm
GetClipboardText PROTO
.code ; code section
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
GetClipboardText proc
push ebx
push esi
push edi
; --------------------------------------------------------
; if the return value is not zero, deallocate the returned
; memory handle with GlobalFree() or the macro "free" when
; the data is no longer required.
; --------------------------------------------------------
invoke OpenClipboard,NULL ; open clipboard
.if rv(IsClipboardFormatAvailable,CF_TEXT) != 0 ; if text available
invoke GetClipboardData,CF_TEXT ; get pointer to text
mov ebx, eax
invoke StrLen,eax ; get text length
mov esi, eax
mov edi, alloc(esi) ; allocate that much memory
cst edi, ebx
invoke CloseClipboard ; close the clipboard
mov eax, edi ; return memory handle
jmp bye
.else ; else
xor eax, eax ; set return to zero
invoke CloseClipboard ; close the clipboard
jmp bye
.endif
bye:
pop edi
pop esi
pop ebx
ret
GetClipboardText endp
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.486 ; maximum processor model
.model flat, stdcall ; memory model & calling convention
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\macros\macros.asm
SetClipboardText PROTO :DWORD
.code ; code section
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
SetClipboardText proc ptxt:DWORD
LOCAL hMem :DWORD
LOCAL pMem :DWORD
LOCAL slen :DWORD
invoke StrLen, ptxt ; get length of text
mov slen, eax
add slen, 64
invoke GlobalAlloc,GMEM_MOVEABLE or \
GMEM_DDESHARE,slen ; allocate memory
mov hMem, eax
invoke GlobalLock,hMem ; lock memory
mov pMem, eax
cst pMem, ptxt ; copy text to allocated memory
invoke OpenClipboard,NULL ; open clipboard
invoke SetClipboardData,CF_TEXT,pMem ; write data to it
invoke CloseClipboard ; close clipboard
invoke GlobalUnlock,hMem ; unlock memory
invoke GlobalFree,hMem ; deallocate memory
ret
SetClipboardText endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end
Hello Hutch,
I tried both modules in masm32 library, unfortunately it does not work properly.
Here are the problems I noted:
1. In "GetClipboardText":
If sClipboardFormatAvailable returns an error (this is not text), CloseClipboard function succeeds, the return value is nonzero, not 0. Ie there will never return error. OpenClipboard should be placed next.
2. In "SetClipboardText"
It seems necessary to use EmptyClipboard before writing with SetClipboardData, otherwise it does not work.
Regards
Quote from: Faiseur on April 23, 2010, 09:49:58 PM
It seems necessary to use EmptyClipboard before writing with SetClipboardData, otherwise it does not work.
A snippet for testing the ret values. Afaik the global memory should
not be freed.
include \masm32\include\masm32rt.inc
printnum MACRO arg, text
LOCAL tmp$
pushad
print str$(arg), 9
print reparg(text), 13, 10
popad
ENDM
.code
MyText db "Hello Masm32", 0
start:
invoke OpenClipboard, 0
invoke EmptyClipboard
printnum eax, "Open"
invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_DDESHARE, sizeof MyText+1
printnum eax, "Alloc"
mov ebx, eax
invoke GlobalLock, eax
push eax
printnum eax, "Lock"
invoke lstrcpy, eax, offset MyText
printnum eax, "lstrcpy"
mov eax, [esp]
invoke GlobalUnlock, eax
printnum eax, "Unlock"
pop eax
invoke SetClipboardData, CF_TEXT, eax
printnum eax, "SetClipboardData"
invoke CloseClipboard
printnum eax, "CloseClipboard"
exit
end start