in reply to Move/Copy files using Clipboard!

This isn't something that can be easily done with win32::API.

If you are setup to build your own packages, you could try applying the following patch to Win32::Clipboard v0.52. It adds a SetFiles() method. It includes the code changes plus an extra test, but no changes to the documentation.

If it proves usable I'll offer it to the owner, but be prepared to back it out. XS isn't my thing.

diff -uiwr Win32-Clipboard-0.52\Clipboard.pm Win32-Clipboard-0.53-save +d\Clipboard.pm --- Win32-Clipboard-0.52\Clipboard.pm Fri Sep 10 16:05:35 2004 +++ Win32-Clipboard-0.53-saved\Clipboard.pm Fri Oct 14 07:01:43 200 +5 @@ -3,10 +3,11 @@ # # Win32::Clipboard - Interaction with the Windows clipboard # -# Version: 0.52 +# Version: 0.53 # Author: Aldo Calpini <dada@perl.it> # # Modified by: Hideyo Imazu <himazu@gmail.com> +# BrowserUk@perlmonks 14 October 2005 Added SetFiles # ##################################################################### +## @@ -65,7 +66,7 @@ ##################################################################### +## # STATIC OBJECT PROPERTIES # -$VERSION = "0.52"; +$VERSION = "0.53"; ##################################################################### +## # FUNCTIONS diff -uiwr Win32-Clipboard-0.52\Clipboard.xs Win32-Clipboard-0.53-save +d\Clipboard.xs --- Win32-Clipboard-0.52\Clipboard.xs Sat Jul 24 09:47:05 2004 +++ Win32-Clipboard-0.53-saved\Clipboard.xs Fri Oct 14 07:00:04 200 +5 @@ -3,12 +3,13 @@ # # Win32::Clipboard - Interaction with the Windows clipboard # -# Version: 0.52 +# Version: 0.53 # Created: 19 Nov 96 # Author: Aldo Calpini <dada@divinf.it> # # Modified: 24 Jul 2004 # By: Hideyo Imazu <h@imazu.net> +# BrowserUk@perlmonks 14 October 2005 Added SetFiles # ##################################################################### +## */ @@ -630,6 +631,69 @@ } void +SetFiles(...) +PPCODE: + HANDLE myhandle; + HGLOBAL hGlobal; + LPTSTR szString; + SV* sv; + int leng = 16; // DROPFILES header + int index; + if(!items) { + XSRETURN_UNDEF; + } + for( index=1; index < items; index++ ) { + sv = ST(index); + leng += SvCUR( sv ); + } + leng += index * 2 +10; + if ( hGlobal = GlobalAlloc(GMEM_DDESHARE, (leng)*sizeof(char)) ) +{ + char* sz = szString = (char *) GlobalLock(hGlobal); + memset( szString, 0, leng );; + + *((INT*)szString) = 20l; // offset to star +t of list + szString += 20l; + + for( index=1; index<items; index++ ) { + sv = ST(index); + leng = SvCUR( sv ); + memcpy(szString, (char *) SvPV_nolen( sv ), leng*sizeof(c +har)); + szString += leng + 1; + } + + GlobalUnlock(hGlobal); + + if ( OpenClipboard(NULL) ) { + EmptyClipboard(); + myhandle = SetClipboardData( CF_HDROP, (HANDLE) hGlobal ) +; + CloseClipboard(); + + if ( myhandle ) { + XSRETURN_YES; + } else { +#ifdef WIN32__CLIPBOARD__DEBUG + printf("XS(Set): SetClipboardData failed (%d)\n", + GetLastError()); +#endif + XSRETURN_NO; + } + } + else { +#ifdef WIN32__CLIPBOARD__DEBUG + printf("XS(Set): OpenClipboard failed (%d)\n", GetLastErr +or()); +#endif + GlobalFree(hGlobal); + XSRETURN_NO; + } + } + else { +#ifdef WIN32__CLIPBOARD__DEBUG + printf("XS(Set): GlobalAlloc failed (%d)\n", GetLastError()); +#endif + XSRETURN_NO; + } + +void Empty(...) PPCODE: if(OpenClipboard(NULL)) { diff -uiwr Win32-Clipboard-0.52\Makefile Win32-Clipboard-0.53-saved\Ma +kefile --- Win32-Clipboard-0.52\Makefile Sat Jul 24 09:48:51 2004 +++ Win32-Clipboard-0.53-saved\Makefile Fri Oct 14 04:45:51 2005 @@ -55,11 +55,11 @@ DIRFILESEP = ^\ NAME = Win32::Clipboard NAME_SYM = Win32_Clipboard -VERSION = 0.52 +VERSION = 0.53 VERSION_MACRO = VERSION -VERSION_SYM = 0_52 +VERSION_SYM = 0_53 DEFINE_VERSION = -D$(VERSION_MACRO)=\"$(VERSION)\" -XS_VERSION = 0.52 +XS_VERSION = 0.53 XS_VERSION_MACRO = XS_VERSION XS_DEFINE_VERSION = -D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\" INST_ARCHLIB = blib\arch @@ -251,7 +245,7 @@ DIST_CP = best DIST_DEFAULT = tardist DISTNAME = Win32-Clipboard -DISTVNAME = Win32-Clipboard-0.52 +DISTVNAME = Win32-Clipboard-0.53 # --- MakeMaker macro section: @@ -502,7 +496,7 @@ $(NOECHO) $(ECHO) "# http://module-build.sourceforge.net/META-spe +c.html" > META.yml $(NOECHO) $(ECHO) "#XXXXXXX This is a prototype!!! It will chang +e in the future!!! XXXXX#" >> META.yml $(NOECHO) $(ECHO) "name: Win32-Clipboard" >> META.yml - $(NOECHO) $(ECHO) "version: 0.52" >> META.yml + $(NOECHO) $(ECHO) "version: 0.53" >> META.yml $(NOECHO) $(ECHO) "version_from: Clipboard.pm" >> META.yml $(NOECHO) $(ECHO) "installdirs: site" >> META.yml $(NOECHO) $(ECHO) "requires:" >> META.yml @@ -824,7 +818,7 @@ # --- MakeMaker ppd section: # Creates a PPD (Perl Package Description) for a binary distribution. ppd: - $(NOECHO) $(ECHO) "<SOFTPKG NAME=\"$(DISTNAME)\" VERSION=\"0,52,0 +,0\">" > $(DISTNAME).ppd + $(NOECHO) $(ECHO) "<SOFTPKG NAME=\"$(DISTNAME)\" VERSION=\"0,53,0 +,0\">" > $(DISTNAME).ppd $(NOECHO) $(ECHO) " <TITLE>$(DISTNAME)</TITLE>" >> $(DISTNAME) +.ppd $(NOECHO) $(ECHO) " <ABSTRACT>Interaction with the Windows cli +pboard</ABSTRACT>" >> $(DISTNAME).ppd $(NOECHO) $(ECHO) " <AUTHOR>Aldo Calpini &lt;dada@perl.it&gt;< +/AUTHOR>" >> $(DISTNAME).ppd diff -uiwr Win32-Clipboard-0.52\META.yml Win32-Clipboard-0.53-saved\ME +TA.yml --- Win32-Clipboard-0.52\META.yml Fri Sep 10 16:08:05 2004 +++ Win32-Clipboard-0.53-saved\META.yml Thu Oct 13 19:32:49 2005 @@ -1,7 +1,7 @@ # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXX +X# name: Win32-Clipboard -version: 0.52 +version: 0.53 version_from: Clipboard.pm installdirs: site requires: diff -uiwr Win32-Clipboard-0.52\t\test.t Win32-Clipboard-0.53-saved\t\ +test.t --- Win32-Clipboard-0.52\t\test.t Sat Mar 11 15:51:26 2000 +++ Win32-Clipboard-0.53-saved\t\test.t Fri Oct 14 04:45:34 2005 @@ -3,11 +3,11 @@ # `make test'. After `make install' it should work as `perl test.pl' use strict; -use vars qw( $loaded $clip $actual ); +use vars qw( $loaded $clip $actual @actual ); ######################### We start with some black magic to print on +failure. -BEGIN { $| = 1; print "1..9\n"; } +BEGIN { $| = 1; print "1..10\n"; } END {print "not ok 1\n" unless $loaded;} use Win32::Clipboard; $loaded = 1; @@ -31,22 +31,27 @@ print "not " unless $clip->Get() eq ""; print "ok 5\n"; +$clip->SetFiles( qw[ 1.dat 2.dat 3.dat 4.dat 5.dat ] ); +@actual = $clip->GetFiles(); +print "not " unless "@actual" eq "1.dat 2.dat 3.dat 4.dat 5.dat"; +print "ok 6\n"; + undef $clip; tie $clip, 'Win32::Clipboard'; print "not" unless tied($clip) and ref(tied($clip)) =~ /Win32::Clipbo +ard/; -print "ok 6\n"; +print "ok 7\n"; $clip = "Win32::Clipboard test"; $actual = $clip; print "not " unless $actual eq "Win32::Clipboard test"; -print "ok 7\n"; +print "ok 8\n"; tied($clip)->Empty(); print "not " unless $clip eq ""; -print "ok 8\n"; +print "ok 9\n"; $clip = "Win32::Clipboard test"; print "not " unless tied($clip)->IsText(); -print "ok 9\n"; \ No newline at end of file +print "ok 10\n";

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Move/Copy files using Clipboard!
by Ace128 (Hermit) on Oct 14, 2005 at 07:20 UTC
    Wow! Hope it will be official soon :)

    But, err, where did you find this patch? Couldn't find that on cpan... only http://search.cpan.org/~jdb/libwin32/Clipboard/Clipboard.pm (which is v0.52)

    Update: Seems like its you're personal update, or?
      But, err, where did you find this patch?

      I just finished writing it. I wanted this myself a couple of years ago, but couldn't get it to work. This time I did.

      Please let me know how you get on with it. If it works for you also, then I'll forward the patch to whomever owns it (there seem to be two owners?), and it's up to them whether they wish to add it.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
        So... you have actually compiled and tested it? Or, how do you know this works? I was planing of looking more into this when I get home today... see if I can add that do clipboard.dll (?) somehow... :) Would actually be a nice learning process... Hard maybe, but yet interesting... Hopefully, I dont have to recompile the whole Win32 module!