News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Clipboard topic

Started by jj2007, June 15, 2020, 06:06:00 PM

Previous topic - Next topic

jj2007

QuoteIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Closing the clipboard should never return zero, unless something has really gone bad. So the correct sequence should be
    .else                                       ; else
      invoke CloseClipboard                     ; close the clipboard
      .if !eax
           invoke GetLastError
           print str$(eax)
           print " error in CloseClipboard
      .endif
      jmp bye               ; eax = 0 or 1 now
    .endif

hutch--

Hi Leonard,

I confess its 13 years since I wrote that procedure but the only useful thing to return if data is available is the GlobalAlloc() memory handle. The .else block for CloseClipboard() is to close the clipboard if the opening call to OpenClipboard() did not fail. You are right that CloseClipboard() overwrites eax so it serves no purpose to zero it above the CloseClipboard() call.

If I was not working in Win 64 assembler, I would rewrite it as it needs to be done differently to make it more reliable.

It should test the return value of OpenClipboard() to ensure another app does not own the clipboard and if it is available and there is no data on the clipboard, it then should close the clipboard then return zero to indicate the the procedure was not able to get data from the clipboard.

TimoVJL

May the source be with you

hutch--

Microsoft seem to think so.