in reply to Windows Clipboard
The first question is: What output do you expect to see from your program when there are no print statements?
Using the raw version of Win32::API is harder work than necessary. Win32::API::Prototype makes life a little easier (though it still has problems).
Finally, the clipboard api set is very badly designed.
Many things about it are very strange. The first is that most of the clipboard formats you will encounter are so-called "pre-defined formats". These do not have a name, just an ID. Attempting to get the name for these formats using GetClipboardName() returns and error. This is documented (kind of).
The CountClipboardFormats() api doesn't tell you how many formats are known to the system. It tells you how many formats the current contents can be converted to.
The EnumClipboardFormats() enumerates the clipboard format IDs that the current contents can be rendered into, though the results I'm getting are...um...strange. This could be my code in error, or my misunderstanding of the api, or an error in the api. I'm not sure which.
Here is a little code for you to play with. Try cutting a few different types of things (some text, a bitmap, some files or directories in the Explorer, an icon) and then run the code.
#! perl -slw use strict; use Win32::API::Prototype; { ## Read the apis from DATA and import them. local $/ = ''; ## Para mode while( <DATA> ) { my( $dll, $proto, $api ) = m[(\w+)\n(\w+\s+(\w+)\(.*)$]s; # print "$dll:[$api]\n'$proto'"; ApiLink( $dll, $proto ) or die "$api : $^E"; } close DATA; } OpenClipboard( 0 ); my $fmts = CountClipboardFormats( 0 ); print "Formats currently available on clipboard: $fmts"; my $formatID = 0; ## To get the first for( 0 .. $fmts ) { my $formatID = EnumClipboardFormats( $formatID ) or die $^E; last unless $formatID; my $fmtName = ' ' x 254; my $length = 254; GetClipboardFormatName( $formatID, $fmtName, $length ) or warn "Format $formatID is pre-defined and does not have an +name.\n" and next; print "Format $formatID is called: $fmtName"; } __DATA__ user32 BOOL OpenClipboard( HWND hWndNewOwner ) user32 int CountClipboardFormats( VOID ) user32 UINT EnumClipboardFormats( UINT format ) user32 int GetClipboardFormatName( UINT format, LPTSTR lpszFormatName, int cchMaxCount ) user32 BOOL CloseClipboard( VOID )
All in all. Using Win32::Clipboard is probably easier for the simple case.
|
|---|