Outlook Drag and Drop
by Wil van Antwerpen
Outlook email drag and drop functionality. Even while you nowadays can have file drag and drop functionality in your Visual DataFlex applications, email drag and drop does not work as of yet.
Unfortunately both are using a complete different approach, this project shows you how-to get it working.
|Size: 224 KB
||Wil van Antwerpen
Please thank the fine people from PP7
for being able to share this projects solution.
They hired me to add Outlook e-mail drag and drop capabilities to VDF for them and suggested to release the final solution with the community.
The project here includes all of the source code used. This includes source in Delphi for a DLL that implements the parts you cannot do in native DataFlex as well as an example project based on the order entry example developed in VDF 17.1.
What does it do?
This project gives you the possibility to drag and drop emails from Outlook onto a control or container in your application and have it extract the email from Outlook directly.
The drag and drop interface that outlook offers is OLE drag and drop
. There is no native interface for this in DataFlex, in fact a lot is missing in VDF for being able to use the technology behind OLE drag and drop.
For example there is no IInterface implementation and none of its descendants such as IDropTarget and IDropSource are part of Visual DataFlex.
As a result the implementation for that part is done in a DLL which is being generated using Delphi 2007.
The DLL sends a notification back to the VDF application to let the application know that a drop was initiated.
Extracting the email
There are ways of decoding the OLE drag and drop and have it decode the OLE stream as initiated by Outlook.
This however consists of a binary -mostly undocumented- stream that needs MAPI in order to decode it.
As some of you might know, the MAPI interface has been deprecated by Microsoft and does not even work when you try to communicate from your 32 bits VDF applicatioin with a 64 bits version of Office 2007 or Office 2010.
Because we needed the solution to work with Outlook 2007 -and newer- the MAPI path was not acceptable. As an alternative the actual retrieval of the selected items from Outlook is being done via COM.
There's a "smallish" subset of the Outlook interface included as "cOutlookReader.pkg" to actually get at the email data.
This subclass has had a number of changes to it so that it should not collide with existing office packages which you already might be using in your application.
The dreaded security measures in Outlook
While the interface was designed to work with Outlook 2007 and newer, it will actually work from Outlook 2003.
This however is not completely without its setback as Outlook 2003 has a security measure built in that will trigger when you try to read anything more as the email subject.
The error is "A program is trying to access e-mail address information stored in Outlook yada yada yada", this security measure will not trigger in Outlook 2007 or higher IF and only IF you have a current antivirus installed, activated and if that antivirus is up to date.
As our target was Outlook 2007 and higher, we did not have to look around for solutions that help to work around the security dialog problem.
Other side requirements
A few other requirements have been:
- the drop target should also be capable of being used as a drop target for files. This means that the VDF control not only needs to accept outlook emails, but also files dragged from Windows Explorer using the native DataFlex pbAcceptDropFiles interface.
- the drop target is a tabpage object. This complicates the control a little bit as a tabpage destroys its windows control when you close the view. If you then open the view again, a new windows tabpage control is being created.
As Windows Explorer implements drag and drop using both the DragAcceptFiles API
and as OLE drag and drop, the DLL needs to block the OLE drag and drop from Windows explorer to be able to use the DragAcceptFiles drop.
Below is a screenshot of the demo in action.
It displays 3 subjects of email messages from Outlook 2007 dragged onto a List control in a tabpage.
At the bottom there are also 3 file names of files from this project drag and dropped from Windows Explorer onto the same control.
Frequently Asked Questions
- I added the drag and drop capability to a few views, when I leave both views open on the same tabpage and switch between the pages, then after switching between the views it seems that I can drop the files on the page, but it does no longer display the dropped files. Eg. the onDropTarget event does not get send.
You can have multiple active drop targets in your application. The problem here is that the event that gets send to your applicaiton needs to know to which DataFlex object the onDropTarget event has to be send. As you are switching the views without closing them, the drop targets never get unregistered so the logic doesn't know.
The easiest workaround is setting the following in your Entering_scope method:
Adding that line will make sure the onDropTarget of the current focused view/container is triggered.
- The example uses Visual DataFlex 17.1. Could this work with earlier VDF versions? i.e. 16.0?
Sure no problem at all.
The only part that is DataFlex version sensitive is the generated FlexCOM2 package for Outlook 2003 called "OutlookBase.pkg".
For VDF versions older as VDF17.1 you -might- have to regenerate the FlexCOM2 packages and re-apply the "find and replace" steps as are outlined at the top of the forementioned package.
- Running the test application from the Studio does not allow me to drop an email from Outlook, it only works when running the test application itself.
Make sure to not run the Studio with administrator rights. Normally Outlook does not run with administrator rights and as a result the security elevation level between your application and Outlook is different. Windows prevents drag & drop between applications running in a different security context.
will be added soon
The demo is made in Visual DataFlex 17.1, the delphi control is made with Delphi 2007.
The Visual DataFlex example has a compiled version of the DLL in the workspace program folder.
Order Entry Example.zip
~ 227 kB
Delphi DLL source code.zip