Thanks. Using your program I was able to deduce that the problem was
coming from
wd 'clipcopy'
followed by a write to the clipboard in another window. Then, the
subsequent call to
wd 'clippaste'
gives domain error.
I experimented with variations on
wd'clipcopy xxx' [ 6!:3(5)
where I would hit ENTER in J, and then during the 5-second delay I would
switch to another window and then do different things there. I find
that the clipcopy succeeds if I do nothing in the other window; it fails
if I CTRL-C to copy text to the clipboard in the other window; it
succeeds if I do both CTRL-C and CTRL-V in the other window. From which
it appears that there is some notion of the owner of the clipboard, and
the active window gets ownership by ctrl-c; and if it's the owner, a
write to the clipboard fails.
When I enhanced the test to
wd 'clippaste' [ 6!:3 (5) [ wd 'clipcopy' [ 6!:3 (5)
I found that if I waited until after the clipcopy (at which time J had
become the clipboard owner), and then went to another window and did
CTRL-C, the clipboard seems to be marked as damaged. Sbsequent
clippaste fails, and the other window doesn't allow a PASTE operation
either.
So, it appears that this is how Windows works, and I just have to work
around it.
In your verb, the call to GetClipboardData also fails in this situation.
The failure seems to be harmless, but here is a version that checks
for it (upgraded to new dll syntax)
NB. y is a clipboard format
getclipdata=: 3 : 0
'user32 OpenClipboard >i x'&cd <0
if. h=. 'user32 GetClipboardData >x i'&cd <y do.
ms=. 'kernel32 GlobalSize >x x'&cd <h
mp=. 'kernel32 GlobalLock >x x'&cd <h
data =. memr mp, 0, ms
'kernel32 GlobalUnlock >i x'&cd <h
else.
data =. ''
end.
'user32 CloseClipboard >i'&cd ''
data
)
bill lam wrote:
> On Sat, 06 Jun 2009, bill lam wrote:
>> I guess that might be a bug in wd. In general wd implicitly works on the
>> current parent form so that you may try using wd'psel ..' before clippaste.
>>
>> Winapi for getting clipboard data.
>>
>> getclipdata=: 3 : 0
>> 'user32 OpenClipboard i x'&cd <0
>> h=. dllrv 'user32 GetClipboardData x i'&cd <y
>> ms=. dllrv 'kernel32 GlobalSize x x'&cd <h
>> mp=. dllrv 'kernel32 GlobalLock x x'&cd <h
>> data=. memr mp, 0, ms
>> 'kernel32 GlobalUnlock i x'&cd <h
>> 'user32 CloseClipboard i'&cd ''
>> data
>> )
>>
>> where dllrv is >@{. because it was written for older J.
>
> I forget to list the argument for getclipdata, eg.
>
> getclipdata CF_TEXT
> 6 u: getclipdata CF_UNICODETEXT
>
> NB. Predefined Clipboard Formats
> CF_TEXT=: 1
> CF_BITMAP=: 2
> CF_METAFILEPICT=: 3
> CF_SYLK=: 4
> CF_DIF=: 5
> CF_TIFF=: 6
> CF_OEMTEXT=: 7
> CF_DIB=: 8
> CF_PALETTE=: 9
> CF_PENDATA=: 10
> CF_RIFF=: 11
> CF_WAVE=: 12
> CF_UNICODETEXT=: 13
> CF_ENHMETAFILE=: 14
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm