Article View: borland.public.cppbuilder.nativeapi
Article #5557Copy Files
From: Alexander Adam
Date: Mon, 08 Aug 2005 00:34
Date: Mon, 08 Aug 2005 00:34
59 lines
2190 bytes
2190 bytes
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?
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);
char* FileList = new char[tmpList.Length() + 1];
try {
strcpy(FileList, tmpList.c_str());
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), FileList, len);
GlobalUnlock(hGbl);
if (!SetClipboardData(CF_HDROP,hGbl)) {
GlobalFree(hGbl);
hGbl = NULL;
}
} else if(hGbl != NULL) {
GlobalFree(hGbl);
hGbl = NULL;
}
CloseClipboard();
return hGbl != NULL;
} __finally {
delete FileList;
}
}
Technical Details
Message-ID:
<42f6a8ab@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a3b46c11acc1d35f,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 08 Aug 2005 02:34:33 +0200 From: Alexander Adam <sdg@dg.dg> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Copy Files Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 217.91.56.77 Message-ID: <42f6a8ab@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1123461291 217.91.56.77 (7 Aug 2005 17:34:51 -0700) Lines: 59 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail