Using CLIPBOARD to store and later paste a list of files/attachments

Thanks chaps. They’ve switched me to another bit of work, but I hope to return to this
later next week.

Carl’s project is very helpful in finding the information items available on the clipboard. Also this utility:

Explorer and Outlook enter data to the clipboard differently, here is an example for both cases:
-Read paths and names of copied files from windows explorer (CF_HDROP)
-Read the names of attached files copied from Outlook 365 and the content of the first one only (FileGroupDescriptor and FileContents)

GetFilesAttachments.clw (3,1 KB)

All done only with the included CLIPBOARD function. In the case of CF_HDROP (copying from the explorer) it uses a single API to convert Unicode to Ansi, so the included support does help, although as you can see in the code, access through APIs is easier in this case.

From Outlook there is a difficulty if you select multiple files to copy. The technique to access the attachments from the second onwards is more complex, to access the lindex field. There is code in the mentioned Devuna Ole Drag and Drop project that references the IDataObject interface GetData method, FORMATETC structure.



https://social.msdn.microsoft.com/Forums/vstudio/en-US/affcf9cd-704d-4ea2-b80b-4c09062af72d/how-extract-an-outlook-attachment-from-the-clipboard-?forum=wpf
2 Likes

It didn’t work with my Outlook 2019, but might not be an issue for the OP. In any event, nice code and I tip my hat to you on almost entirely avoiding accessing the winapi directly! :+1:

Thanks, perhaps Outlook 2019 has a different number in DataObject, try with these changes:
GetFilesAttachments.clw (3,1 KB)
if it doesn’t work, it would worth running Carl’s tool to see what elements are in the clipboard.

This is what Carl’s tool returns – and one reason I have as little to do with Outlook as possible. There’s no consistency in anything they do!

Format# Format Name
49161 DataObject
49171 Ole Private Data
49275 FileContents
49288 FileGroupDescriptor
49289 FileGroupDescriptorW
49312 ZoneIdentifier
49625 RenPrivateItem

@CarlBarnes Nice tool, by the way!

1 Like

A better way would be to first enumerate the formats (as Carl’s tool do) and choose by name, but as for the non api example, another technique could be to test some specific formats like this new example: GetFilesAttachments.clw (3,8 KB)

It relies on filedescriptor being on 72+256 character blocks though, this is easier to see with the Free Clipboard Viewer tool.

Outlook 2003 numbers seen here https://forum.powerbasic.com/forum/user-to-user-discussions/special-interest-groups/programming-microsoft-office/46181-clipboard-data-from-outlook-attachments

Edit. Enumeration seems mandatory as those number changes on reboots. RegisterClipboardFormat only receives the string parameter so it may be taking first free numbers in a range.

2 Likes