AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Odd Clipboard related error

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
ManaUser



Joined: 24 May 2007
Posts: 900

PostPosted: Fri Aug 10, 2007 7:24 am    Post subject: Odd Clipboard related error Reply with quote

I'm getting "Error: GetClipboardData" when I access the Clipboard variable when certain contents are in the clipboard. Specifically when the clipboard contains a Firefox bookmark folder. Normally, Clipboard should just be blank if there's no text in the clipboard, right? Here's the script I was using.
Code:
AppsKey & v::
;Paste as text
If (ClipBoard != "")
   PutText(ClipBoard)
Return

PutText(MyText)
{
   SavedClip := ClipboardAll
   Clipboard := MyText
   Send ^v
   Sleep 100
   Clipboard := SavedClip
   Return
}

These steps should reproduce the error:
Start Firefox, click the Bookmarks menu, right-click "Bookmarks Toolbar Folder", select Copy, run the script above, and press AppsKey+V.
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1090
Location: USA

PostPosted: Fri Aug 10, 2007 10:22 pm    Post subject: Reply with quote

Confim the error.

Get the same error with this.
Code:
AppsKey & v::
abc := Clipboard
return
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3941
Location: Pittsburgh

PostPosted: Fri Aug 10, 2007 10:56 pm    Post subject: Reply with quote

It happens to me, too.
- It does not matter what hotkey I use
- I tried #ClipboardTimeout 10000 (10 sec), the only difference is that the error dialog appears later.
- The clipboard does contain data. If I paste it into Word, I get Bookmarks Toolbar Folder
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3941
Location: Pittsburgh

PostPosted: Fri Aug 10, 2007 11:14 pm    Post subject: Reply with quote

If you use "abc := ClipboardAll", there is no error, but, of course, you don't see the text content of the clipboard, either.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1240

PostPosted: Sat Aug 11, 2007 2:20 am    Post subject: Reply with quote

I'm not sure if it's an AHK's fault. When doing this with firefox, the clipboard is really populated by firefox. The available formats are:
moz/bookmarkclipboarditem, text/html, HTML Format, CF_UNICODETEXT, CF_TEXT.
The first three are custom formats and contain actual data, i.e., the type of the storage medium is TYMED_HGLOBAL, so no problem with GetClipboardData.
However, the last two are of type TYMED_NULL, i.e., no actual data has been passed. Thus, GetClipboardData produced errors on these, naturally.
Refer the link for more detail:
http://msdn2.microsoft.com/en-us/library/ms691227.aspx
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3941
Location: Pittsburgh

PostPosted: Sat Aug 11, 2007 3:41 am    Post subject: Reply with quote

In the AHK assignment x := ClipBoard the CF_TEXT format is used, isn't it? Was not it easy to check, if its content is TYMED_NULL, and if yes, assign the empty string to x? In MS Word I can Paste Special / Unformatted text, which does not crash or give an error, but pastes nothing. This should happen in AHK, too.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1240

PostPosted: Sat Aug 11, 2007 4:37 am    Post subject: Reply with quote

Laszlo wrote:
In the AHK assignment x := ClipBoard the CF_TEXT format is used, isn't it? Was not it easy to check, if its content is TYMED_NULL, and if yes, assign the empty string to x? In MS Word I can Paste Special / Unformatted text, which does not crash or give an error, but pastes nothing. This should happen in AHK, too.

The ordinary Clipboard APIs can't get infos about the storage medium types.
Have to use OLE's clipboard functions, OleGetClipboard etc, and deal with a COM object IDataObject.
I'll post a sample script on these later.
Back to top
View user's profile Send private message
ManaUser



Joined: 24 May 2007
Posts: 900

PostPosted: Sat Aug 11, 2007 4:53 am    Post subject: Reply with quote

Laszlo wrote:
In the AHK assignment x := ClipBoard the CF_TEXT format is used, isn't it? Was not it easy to check, if its content is TYMED_NULL, and if yes, assign the empty string to x? In MS Word I can Paste Special / Unformatted text, which does not crash or give an error, but pastes nothing. This should happen in AHK, too.

Exactly. It does sound like Firefox is using the clipboard oddly, but from an AHK user/programmer's point of view, I need to know that I can always safely access the clipboard, even when it doesn't contain usable text. (In which case it should be blank.)

It also causes an error if I run this and then copy a bookmark folder.
Code:
ClipBoard =
ClipWait
MsgBox %ClipBoard%

So the TYMED_NULL CF_TEXT apparently fools ClipWait too.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1240

PostPosted: Sat Aug 11, 2007 12:43 pm    Post subject: Reply with quote

ManaUser wrote:
Exactly. It does sound like Firefox is using the clipboard oddly, but from an AHK user/programmer's point of view, I need to know that I can always safely access the clipboard, even when it doesn't contain usable text. (In which case it should be blank.)

IMO, AHK or Chris was too innocent.
If there was an error to obtain hGlobal, could just ignore it and you'd never notice about it (:no offense intended here).
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10463

PostPosted: Sat Aug 18, 2007 12:46 am    Post subject: Reply with quote

If it seems okay with everyone, the next release will have the following change:

Eliminated the "GetClipboardData" error dialog. Instead, an empty string is retrieved when the data cannot be retrieved within the #ClipboardTimeout period.

This seems unlikely to break many (if any) existing scripts. But please let me know if you see any problems with it.

Thanks for all the detailed posts about it.
Back to top
View user's profile Send private message Send e-mail
ManaUser



Joined: 24 May 2007
Posts: 900

PostPosted: Tue Aug 21, 2007 7:17 pm    Post subject: Reply with quote

Certainly sounds good to me.
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 400
Location: Galil, Israel

PostPosted: Wed Aug 22, 2007 4:13 pm    Post subject: Reply with quote

second that,

maybe also set errorlevel in such a case...
_________________
Joyce Jamce
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group