1 package org.jinterop.dcom.test; 2 3 import java.net.UnknownHostException ; 4 5 import org.jinterop.dcom.common.JIException; 6 import org.jinterop.dcom.common.JISystem; 7 import org.jinterop.dcom.core.IJIComObject; 8 import org.jinterop.dcom.core.JICallObject; 9 import org.jinterop.dcom.core.JIComServer; 10 import org.jinterop.dcom.core.JIFlags; 11 import org.jinterop.dcom.core.JIInterfacePointer; 12 import org.jinterop.dcom.core.JIProgId; 13 import org.jinterop.dcom.core.JISession; 14 import org.jinterop.dcom.core.JIVariant; 15 import org.jinterop.dcom.win32.ComFactory; 16 import org.jinterop.dcom.win32.IJIDispatch; 17 18 public class MSOutLookExpressContacts { 19 20 JISession session = null; 21 JIComServer comServer = null; 22 23 MSOutLookExpressContacts(String args[]) throws UnknownHostException , JIException 24 { 25 session = JISession.createSession(args[1],args[2],args[3]); 26 comServer = new JIComServer(JIProgId.valueOf(session,"Outlook.Application"),args[0],session); 27 } 28 29 void doStuff() throws JIException 30 { 31 IJIComObject unknown = (IJIComObject)comServer.createInstance(); 32 IJIComObject application = (IJIComObject)unknown.queryInterface("00063001-0000-0000-C000-000000000046"); 33 34 JICallObject callObject = new JICallObject(application.getIpid(),!application.isDispatchSupported()); 35 callObject.setOpnum(12); 36 callObject.addInParamAsString("MAPI", JIFlags.FLAG_REPRESENTATION_STRING_BSTR); 37 callObject.addOutParamAsType(JIInterfacePointer.class,JIFlags.FLAG_NULL); 38 Object [] res = application.call(callObject); 39 40 IJIComObject namespace = ComFactory.createCOMInstance(application,(JIInterfacePointer)res[0]); 41 callObject = new JICallObject(namespace.getIpid()); 42 callObject.setOpnum(16); 43 callObject.addOutParamAsType(JIInterfacePointer.class,JIFlags.FLAG_NULL); 44 res = namespace.call(callObject); 45 46 if (res[0] == null) 47 { 48 System.out.println("user cancelled request"); 49 return; 50 } 51 52 IJIComObject folder = ComFactory.createCOMInstance(application,(JIInterfacePointer)res[0]); 53 callObject = new JICallObject(folder.getIpid()); 54 callObject.setOpnum(4); 55 callObject.addOutParamAsType(Integer .class,JIFlags.FLAG_NULL); 56 res = folder.call(callObject); 57 58 if (((Integer )res[0]).intValue() != 2) 59 { 60 System.out.println("Invalid folder selected, this is not a \"contact\" folder , please reselect.."); 61 return; 62 } 63 64 callObject.reInit(); 65 callObject.setOpnum(10); 66 callObject.addOutParamAsType(JIInterfacePointer.class,JIFlags.FLAG_NULL); 67 res = folder.call(callObject); 68 if (res[0] == null) 69 { 70 System.out.println("Unable to get Contact Items."); 71 return; 72 } 73 74 IJIComObject items = ComFactory.createCOMInstance(application,(JIInterfacePointer)res[0]); 75 callObject = new JICallObject(items.getIpid()); 76 callObject.setOpnum(12); 77 callObject.addOutParamAsType(JIInterfacePointer.class,JIFlags.FLAG_NULL); 78 res = items.call(callObject); 79 80 while(true) 81 { 82 if (res[0] == null) 83 { 84 break; 85 } 86 87 String details = null; 88 IJIDispatch contactItem = (IJIDispatch)ComFactory.createCOMInstance(application,(JIInterfacePointer)res[0]); 89 JIVariant res2 = contactItem.get("FullName"); 90 details = res2.getObjectAsString().getString(); 95 96 res2 = contactItem.get("Email1Address"); 101 details = details + "<" + res2.getObjectAsString().getString() + ">"; 102 103 System.out.println(details); 104 105 callObject = new JICallObject(items.getIpid()); 106 callObject.setOpnum(14); 107 callObject.addOutParamAsType(JIInterfacePointer.class,JIFlags.FLAG_NULL); 108 res = items.call(callObject); 109 } 110 111 } 112 113 public static void main(String [] args) { 114 if (args.length < 4) 115 { 116 System.out.println("Please provide address domain username password"); 117 return; 118 } 119 JISystem.setAutoRegisteration(true); 120 try { 121 MSOutLookExpressContacts outlookMessages = new MSOutLookExpressContacts(args); 122 outlookMessages.doStuff(); 123 JISession.destroySession(outlookMessages.session); 124 } catch (UnknownHostException e) { 125 e.printStackTrace(); 127 } catch (JIException e) { 128 e.printStackTrace(); 130 } 131 132 } 133 134 } 135 | Popular Tags |