🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5576

Re: Copy Files

#5576
From: Jonathan Benedicto
Date: Tue, 09 Aug 2005 16:28
72 lines
2927 bytes
"Alexander Adam" <sdg@dg.dg> wrote in message 
news:42f6a8ab@newsgroups.borland.com...
> hi!
>
> I am trying to copy a list of files into the clipboard. In the following 
> is my code but it doesn't work (acess error with memory or something that 
> the CodeGuard tells me).. any clue or maybe some more simple code to do 
> what I want?

I don't know anything about copying files to the clipboard, but I did 
revise your code to be simpler, and I think that it might work.

// Untested.

AnsiString ShellConcatFiles( TStrings *sourceFiles )
{
        AnsiString tmpStr;
        for( int i = 0; i < sourceFiles->Count; ++i )
        {
                tmpStr += sourceFiles->Strings[i];
                tmpStr += '\0';
        }

        return tmpStr;
}

bool CopyFilesToClipboard( TStrings *sourceFiles )
{
        AnsiString tmpList = ShellConcatFiles( sourceFiles );
        int len;
        BYTE* pData;
        HGLOBAL hGbl;
        DROPFILES hf;

        if( !OpenClipboard( 0 ) )
                return false;

        EmptyClipboard();

        hf.fNC = false;
        hf.fWide = false;
        hf.pFiles = sizeof( hf );
        hf.pt.x = hf.pt.y = 0;

        len = tmpList.Length() + 2;
        hGbl = GlobalAlloc(GHND, sizeof(hf) + len );
        pData = (BYTE*)GlobalLock( hGbl );
        if( pData != NULL )
        {
                memcpy(pData, &hf, sizeof( hf ));
                memcpy(pData + sizeof( hf ), tmpList.c_str(), len );
                GlobalUnlock( hGbl );

                if( !SetClipboardData( CF_HDROP, hGbl ) )
                {
                        GlobalFree(hGbl);
                        hGbl = NULL;
                }
        }
        else if( hGbl != NULL )
        {
                GlobalFree(hGbl);
                hGbl = NULL;
        }

        CloseClipboard();
        return ( hGbl != NULL );
}

HTH

Jonathan 
Technical Details
Message-ID: <42f8d9a0$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42f6a8ab@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a3b46c11acc1d35f
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Jonathan Benedicto" <incorrect@no.server>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <42f6a8ab@newsgroups.borland.com>
Subject: Re: Copy Files
Date: Tue, 9 Aug 2005 12:28:16 -0400
Lines: 74
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 69.158.125.26
Message-ID: <42f8d9a0$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1123604896 69.158.125.26 (9 Aug 2005 09:28:16 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail