News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

QE 4.0f update

Started by hutch--, July 15, 2010, 03:46:42 AM

Previous topic - Next topic

jj2007

#15
Here is a slightly shorter version. By the way: what is the function of "jmp bye"?

include \masm32\include\masm32rt.inc

.code
start: call GetClipboardText
.if eax
push eax
MsgBox 0, eax, "From the clipboard:", MB_OK
call GlobalFree
.if eax
MsgBox 0, "Error", "Hi", MB_OK
.endif
.else
MsgBox 0, "No text on clipboard", "Hi", MB_OK
.endif
mov eax, GetClipboardText_endp
sub eax, GetClipboardText_s
MsgBox 0, str$(eax), "Hi", MB_OK
exit

GetClipboardText_s:
GetClipboardText proc
    ; --------------------------------------------------------
    ; 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.
    ; --------------------------------------------------------
  .if rv(IsClipboardFormatAvailable,CF_TEXT)
.if rv(OpenClipboard, 0)
invoke GetClipboardData, CF_TEXT
push eax ; src for lstrcpy
.if eax
invoke szLen, eax
inc eax ; one more for the zero delimiter
push alloc(eax) ; create dest for lstrcpy
call lstrcpy
push eax ; lstrcpy returns ptr to buffer
.endif
invoke CloseClipboard
pop eax
.endif
  .endif
  ret
GetClipboardText endp
GetClipboardText_endp:
end start


Edit: Had to post an update because the first version was excessively bloated. This one has just under 4*16 bytes :bg

cork

This is the bug, probably... you set EAX=0, then call CloseClipboard which stomps EAX, setting EAX=1. In essence you are expecting a 0 to be returned in EAX and getting a 1 instead.

      xor eax, eax                              ; set return to zero
      invoke CloseClipboard                     ; close the clipboard
      jmp bye

Should be

      invoke CloseClipboard                     ; close the clipboard
      xor eax, eax                              ; set return to zero
      jmp bye

I just looked at the replies and it looks like dedndave spotted the problem, first...

jj2007

Quote from: Yuri on July 17, 2010, 12:19:27 PM
Btw, IsClipboardFormatAvailable seems to work without opening the clipboard.

Correct. I have adjusted my version accordingly :U

ramguru

Minor bug: if .asm file is dropped (into QE) instead of opened using OpenDialog, current directory becomes /masm32/ and .obj file is created there & later not found by batch file

hutch--

There is a menu option to set the current directory. The defect in your logic comes when more than 1 file is dropped into the editor. If it changed directory each time a file was dropped into it it would be very difficult to keep track of the current directory.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php