I am trying to get a copied attachment (through ctrlL+c) from clipboard in outlook 2016. Following code is what I use and is functional for all outlook versions except for 2016. This method is being called when the user simulates a copy through CTRL+C.
void GetClipBoardFiles()
{
// Getting the outlook process id using windows API
int outlookProccessId = GetProcessCurrent();
// getting the clipboard process id using windows API
IntPtr hwndClipboardOwner = GetClipboardOwner();
// getting owners process id of clipboard using windows API
uint processClipboardOwner = GetProcessFromWindowHandle(hwndClipboardOwner);
// If clipboard owner and outlook process id is equal, this copy is done within outlook.
if (outlookProccessId == processClipboardOwner)
{
string[] fileNames = null;
// Check for the available files details in clipboard
if (Clipboard.ContainsFileDropList())
{
// my custom code.
}
}
}
Above code works fine in outlook 2003,2007,2010 and 2013 but for Outlook 2016, sometimes this code does not work. Even though the ctrl+C is simulated in outlook, owner's process id of clipboard do not match with outlook process id. Even it matches, Clipboard.ContainsFileDropList()
method returns false while i can really paste the content which i copied to some folder or desktop.
Is it something to do with a new behavior of Outlook 2016 ? are there any accurate ways to get the clipboard contents copied in Outlook.