Ejemplo n.º 1
0
 private static IAddrBook ADX_GetAddrBook()
 {
     if (MAPI.MAPIInitialize(IntPtr.Zero) == MAPI.S_OK)
     {
         IntPtr sessionPtr = IntPtr.Zero;
         MAPI.MAPILogonEx(0, null, null, MAPI.MAPI_EXTENDED | MAPI.MAPI_ALLOW_OTHERS, out sessionPtr);
         if (sessionPtr == IntPtr.Zero)
         {
             MAPI.MAPILogonEx(0, null, null, MAPI.MAPI_EXTENDED | MAPI.MAPI_NEW_SESSION | MAPI.MAPI_USE_DEFAULT, out sessionPtr);
         }
         if (sessionPtr != IntPtr.Zero)
         {
             try {
                 object sessionObj = Marshal.GetObjectForIUnknown(sessionPtr);
                 if (sessionObj != null)
                 {
                     try {
                         IMAPISession session = sessionObj as IMAPISession;
                         if (session != null)
                         {
                             IntPtr addrBookPtr = IntPtr.Zero;
                             session.OpenAddressBook(0, IntPtr.Zero, MAPI.AB_NO_DIALOG, out addrBookPtr);
                             if (addrBookPtr != IntPtr.Zero)
                             {
                                 try {
                                     object addrBookObj = Marshal.GetObjectForIUnknown(addrBookPtr);
                                     if (addrBookObj != null)
                                     {
                                         return(addrBookObj as IAddrBook);
                                     }
                                 }
                                 finally {
                                     Marshal.Release(addrBookPtr);
                                 }
                             }
                         }
                     }
                     finally {
                         Marshal.ReleaseComObject(sessionObj);
                     }
                 }
             }
             finally {
                 Marshal.Release(sessionPtr);
             }
         }
     }
     else
     {
         throw new ApplicationException("MAPI can not be initialized.");
     }
     return(null);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (session_ != null)
         {
             if (CurrentStore != null)
             {
                 CurrentStore.Dispose();
                 CurrentStore = null;
             }
             if (content_ != null)
             {
                 content_.Dispose();
                 content_ = null;
             }
             Marshal.ReleaseComObject(session_);
             session_ = null;
             MAPINative.MAPIUninitialize();
         }
     }
 }
        /// <summary>
        /// MAPI session intialization and logon.
        /// </summary>
        /// <returns>true if successful; otherwise, false</returns>
        private bool Initialize()
        {
            IntPtr pSession = IntPtr.Zero;
            if (MAPINative.MAPIInitialize(IntPtr.Zero) == HRESULT.S_OK)
            {
                MAPINative.MAPILogonEx(0, null, null, (uint)(MAPIFlag.EXTENDED | MAPIFlag.USE_DEFAULT), out pSession);
                if (pSession == IntPtr.Zero)
                    MAPINative.MAPILogonEx(0, null, null, (uint)(MAPIFlag.EXTENDED | MAPIFlag.NEW_SESSION | MAPIFlag.USE_DEFAULT), out pSession);
            }

            if (pSession != IntPtr.Zero)
            {
                object sessionObj = null;
                try
                {
                    sessionObj = Marshal.GetObjectForIUnknown(pSession);
                    session_ = sessionObj as IMAPISession;
                }
                catch { }
            }

            return session_ != null;
        }
 /// <summary> 
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (session_ != null)
         {
             if (CurrentStore != null)
             {
                 CurrentStore.Dispose();
                 CurrentStore = null;
             }
             if (content_ != null)
             {
                 content_.Dispose();
                 content_ = null;
             }
             Marshal.ReleaseComObject(session_);
             session_ = null;
             MAPINative.MAPIUninitialize();
         }
     }
 }
Ejemplo n.º 5
0
        private void DisposeMapiStuff()
        {
            foreach (TreeNode node in treeFolders.Nodes) {
                DisposeMapiNode(node);
            }

            if (_session != null) {
                _session.Logoff(this.Handle, 0);
                _session.Dispose();
                _session = null;
            }
        }
Ejemplo n.º 6
0
 /// <summary> 
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (session_ != null)
         {
             Marshal.ReleaseComObject(session_);
             session_ = null;
             MAPINative.MAPIUninitialize();
         }
     }
 }
 public MAPIAdviseSink(IMsgStore store, EEventMask eventMask, IMAPISession owner)
 {
     this.store = store;
     IntPtr ptr = IntPtr.Zero;
     this.callbackHandler = OnNotifyCallback;
     HRESULT hr = MAPIlibAdvise(store.Ptr, eventMask, this.callbackHandler, ref ptr);
     if (hr != HRESULT.S_OK)
         throw new Exception("MAPIlibAdvise failed: " + hr.ToString());
     this.adviserPtr = ptr;
     this.owner = owner;
 }
Ejemplo n.º 8
0
 public MsgStore(IntPtr pMsgStore, IMAPISession session)
     : base(pMsgStore)
 {
     this.session = session;
 }