#!perl -w use strict; use Win32::API; use Win32::Clipboard; use 5.006; our $registerClipboardFormat = Win32::API::More->new( 'user32', 'RegisterClipboardFormat', 'P', 'I' ); die "$^E" unless $registerClipboardFormat; #int WINAPI GetClipboardFormatName( # _In_ UINT format, # _Out_ LPTSTR lpszFormatName, # _In_ int cchMaxCount #); our $_getClipboardFormatName = Win32::API::More->new( 'user32', 'GetClipboardFormatName', 'IPI', 'I' ); die "$^E" unless $_getClipboardFormatName; sub getClipboardFormatName { my( $format ) = @_; my $buffer = "\0" x 1024; my $addr = unpack 'I', pack 'P', $buffer; #print $addr; warn $format; return "" if $format < 17; # CF_MAX $_getClipboardFormatName->Call( $format, $buffer, length $buffer ) or die $^E; $buffer =~ s/\0+$//; $buffer } our $CF_HTML; sub CF_HTML() { $CF_HTML ||= do { $registerClipboardFormat->Call("HTML Format"); }; } my $cb = Win32::Clipboard->new(); for my $fmt ($cb->EnumFormats()) { print getClipboardFormatName( $fmt ), "\n"; }; warn "Retrieving as " . CF_HTML(); print $cb->GetAs(CF_HTML()); print "\ndone\n";