Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Automating Outlook

Has anybody tried automating Outlook?
 
I can get it to work... with some workarounds (see below)
 
I'm suspecting that some or all of the problems have to do with Outlook not running in the same process as the Java code. After all, if SWT's COM support is primarily designed for in-process ActiveX controls, then I might be pushing things a bit. However, it's appears to work very well, and it is extraordinarily powerful.
 
Should I be worried about any other potential pitfalls? For example, is SWT properly adding/removing references to all automation objects, even if they are out-of-process?
 
 
Problem 1)
 
The following code only works if Outlook is already running:
 
        Shell shell = new Shell();
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        OleControlSite oleControlSite = new OleControlSite(frame, SWT.NONE, "Outlook.Application");
However, if Outlook isn't already running, then OleControlSite throws an exception.
 
My workaround is to create a little ActiveX control that gets the running Outlook instance for me.  The ActiveX control declares a function called "GetApplication", which returns an OleAutomation object of the Outlook Application. Now I'm able to traverse the Outlook object model nicely.... up to a point!
 
 
Problem 2)
 
Events don't get fired back. I attach listeners to the Application object, but nothing happens.
 
I worked around the problem by declaring similar events in my custom ActiveX control. It listens to Outlook and then fires an event of its own. My Java code listens to events of the custom ActiveX control.
 
 
 
Problem 3)
 
Although I can access lots of Outlook objects, I find that none of the functions with optional parameters work. For example, Attachments.Add() returns null:
 
            int[] rgdispid = attachments.getIDsOfNames(new String[]{"Add", "Source", "Type", "Position", "DisplayName"});
            int dispIdMember = rgdispid[0];
            Variant[] rgvarg = new Variant[3];
            int[] rgdispidNamedArgs = new int[3];
 
            rgvarg[0] = new Variant("C:\\foo.txt"); // this is the Source parameter
            rgdispidNamedArgs[0] = rgdispid[1];

            rgvarg[1] = new Variant(0x1); // this is the Type parameter
            rgdispidNamedArgs[1] = rgdispid[2];

            rgvarg[2] = new Variant("Hello!"); // this is the DisplayName parameter
            rgdispidNamedArgs[2] = rgdispid[4];

            Variant result = attachments.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
Once again, my workaround is to declare a specialized function in the custom ActiveX control.
 
 
 
 

Back to the top