procedure CopyFilesToClipboard(FileList:
string);
var
DropFiles: PDropFiles;
hGlobal: THandle;
iLen: Integer;
begin
iLen := Length(FileList);
hGlobal := GlobalAlloc(GMEM_SHARE
or GMEM_MOVEABLE
or GMEM_ZEROINIT, SizeOf(TDropFiles) + ((iLen + 2) * SizeOf(Char)));
if (hGlobal = 0)
then raise Exception.Create('
Could not allocate memory.');
try
DropFiles := GlobalLock(hGlobal);
try
DropFiles^.pFiles := SizeOf(TDropFiles);
DropFiles^.fWide := True;
if FileList <> '
'
then
Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen * SizeOf(Char));
finally
GlobalUnlock(hGlobal);
end;
Clipboard.SetAsHandle(CF_HDROP, hGlobal);
except
GlobalFree(hGlobal);
end;
end;