⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cemapi.cs

📁 清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码
💻 CS
字号:
using System;
using System.Runtime.InteropServices;

namespace COMInterop
{
    internal static class NativeMethods
    {
        [DllImport("cemapi.dll")]
        internal static extern int MAPIInitialize(IntPtr lpMapiInit);

        [DllImport("cemapi.dll")]
        internal static extern int MAPIUninitialize();

        [DllImport("cemapi.dll")]
        internal static extern int MAPILogonEx(int ulUIParam, string lpszProfileName, string lpszPassword, int flFlags, out IntPtr lppSession);

        [DllImport("cemapi.dll")]
        internal static extern int MailDisplayMessage(byte[] lpEntryID, int cbEntryID);
    }

    [ComImport, Guid("00020300-0000-0000-C000-000000000046"),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IMAPISession
    {
        void GetLastError();//Not supported

        void GetMsgStoresTable(int ulFlags, out IntPtr lppTable);

        void OpenMsgStore(int ulUIParam, int cbEntryID, byte[] lpEntryID,
                int lpInterface, int ulFlags, out IntPtr lppMDB);

        void OpenAddressBook();//Not supported
        void OpenProfileSection();//Not supported
        void GetStatusTable();//Not supported

        void OpenEntry(int cbEntryID, byte[] lpEntryID, int lpInterface, int ulFlags,
                out int lpulObjType, out IntPtr lppUnk);

        void CompareEntryIDs(Int32 cbEntryID1, byte[] lpEntryID1,
                Int32 cbEntryID2, byte[] lpEntryID2,
                int ulFlags, out int lpulResult);

        void Advise(int cbEntryID, byte[] lpEntryID, fnev ulEventMask, IMAPIAdviseSink lpAdviseSink, out int FlpulConnection);

        void Unadvise(int ulConnection);

        void MessageOptions();//Not supported
        void QueryDefaultMessageOpt();//Not supported
        void EnumAdrTypes();//Not supported
        void QueryIdentity();//Not supported

        void Logoff(int ulUIParam, int ulFlags, int ulReserved);

        void SetDefaultStore();//Not supported           
        void AdminServices();//Not supported     
        void ShowForm();//Not supported    
        void PrepareForm();//Not supported    

    }

    [ComImport, Guid("00020302-0000-0000-C000-000000000046"),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IMAPIAdviseSink
    {
        void OnNotify(uint cNotif, ref NOTIFICATION lpNotifications);
    }

    [Flags()]
    internal enum fnev
    {
        ObjectCopied = 0x00000040, //Registers for notifications about an object being copied.  
        ObjectCreated = 0x00000004, //Registers for notifications about the creation of a new object.  
        ObjectDeleted = 0x00000008, //Registers for notifications about an object being deleted. 
        ObjectModified = 0x00000010, //Registers for notifications about an object being modified.  
        ObjectMoved = 0x00000020, //Registers for notifications about an object being moved.  
    }

    [StructLayout(LayoutKind.Explicit)]
    internal struct NOTIFICATION
    {
        [FieldOffset(0)]
        public fnev   ulEventType;        /* notification type, i.e. fnevSomething */
        //uint   ulAlignPad;         /* Force to 8-byte boundary */

    //union
    //{
        //ERROR_NOTIFICATION          err;
        [FieldOffset(8)]
        public NEWMAIL_NOTIFICATION        newmail;
        //OBJECT_NOTIFICATION         obj;
        //TABLE_NOTIFICATION          tab;
        //EXTENDED_NOTIFICATION       ext;
        //STATUS_OBJECT_NOTIFICATION  statobj;
    //} info;
    }

    internal struct NEWMAIL_NOTIFICATION
    {
        public int cbEntryID;
        public IntPtr lpEntryID;          /* identifies the new message */
        public int cbParentID;
        public IntPtr lpParentID;         /* identifies the folder it lives in */
        public uint ulFlags;            /* 0 or MAPI_UNICODE */
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpszMessageClass;   /* message class (UNICODE or string8) */
        public uint ulMessageFlags;     /* copy of PR_MESSAGE_FLAGS */
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -