When dragging an attachment from the New Outlook to Windows Explorer the file gets dropped* at that location, when dragging an email from the New Outlook to Windows Explorer, the file gets dropped* at that location after dismissing a security warning in Outlook. (* dropped means it gets copied from %temp%\chrome_drag_<pid of webview2 exe>_<somenumber>\ to its final destination.)
I want to handle those drops in my Delphi application. I have a droptarget, but when enumerating the data formats I get the following:
I can parse the last format, it gives me ids which I assume can be used to download the email or attachment via Microsoft Graph, but that requires interaction with Microsoft Graph, Windows Explorer doesn't need that and I don't want to.
My hopes are with CF_HDROP, but dataObj.GetData fails with a DV_E_FORMATETC error code.
My code:
procedure TSACustomDropTarget.DoDrop(const dataObj: IDataObject; grfKeyState: Integer; pt: TPoint; var dwEffect: Integer);
var
lFormat: TFormatEtc;
lMedium: TStgMedium;
begin
lFormat.cfFormat := CF_HDROP;
lFormat.ptd := nil;
lFormat.dwAspect := DVASPECT_CONTENT;
lFormat.lindex := -1;
lFormat.tymed := TYMED_HGLOBAL;
if dataObj.GetData(lFormat, lMedium) = S_OK then // Returns DV_E_FORMATETC, but dataObj.GetQueryData(lFormat) returns S_OK
begin
// Get files using DragQuery...
end;
end;
How can I get CF_HDROP to work, or is there another way to get the file from New Outlook?
I finally figured it out. You can only retrieve CF_HDROP when using Async Drag and Drop. So in the Drop handler, check if dataObj supports IDataObjectAsyncCapability, if so, check if Async is possible. When everything checks out, call StartOperation. Fire up a thread and exit the Drop handler. In your thread you can retrieve CF_HDROP as you would normally do. When finishing your thread, call EndOperation.
PS: Beware, to use the IDataObject and IDataObjectAsyncCapability objects you retrieved in de Drop method in another thread, you need to create IAgileReferences to those objects and resolve those in the thread, otherwise you will get RPC_E_WRONG_THREAD errors. I got stuck on this for a long time.
PS2: The New Outlook will show a dialog when dragging emailmessages to your (Delphi) app. GetData will block until the user answers the dialog. So good luck handling that scenario.