#ifndef _MAPIX_H
#define _MAPIX_H

/* Extended Messaging Applications Programming Interface (MAPI) definitions */

#include <mapidefs.h>
#include <mapicode.h>
#include <mapiguid.h>
#include <mapitags.h>

#ifdef  __cplusplus
extern "C" {
#endif

#ifndef BEGIN_INTERFACE
#define BEGIN_INTERFACE
#endif

DECLARE_MAPI_INTERFACE_PTR(IProfAdmin,LPPROFADMIN);
DECLARE_MAPI_INTERFACE_PTR(IMsgServiceAdmin,LPSERVICEADMIN);
DECLARE_MAPI_INTERFACE_PTR(IMAPISession,LPMAPISESSION);

typedef ULONG FLAGS;

#define MAPI_LOGON_UI  0x00000001
#define MAPI_NEW_SESSION  0x00000002
#define MAPI_ALLOW_OTHERS  0x00000008
#define MAPI_EXPLICIT_PROFILE  0x00000010
#define MAPI_EXTENDED  0x00000020
#define MAPI_FORCE_DOWNLOAD  0x00001000
#define MAPI_SERVICE_UI_ALWAYS  0x00002000
#define MAPI_NO_MAIL  0x00008000
#ifndef MAPI_PASSWORD_UI
#define MAPI_PASSWORD_UI  0x00020000
#endif
#define MAPI_TIMEOUT_SHORT  0x00100000

#define MAPI_SIMPLE_DEFAULT  (MAPI_LOGON_UI|MAPI_FORCE_DOWNLOAD|MAPI_ALLOW_OTHERS)
#define MAPI_SIMPLE_EXPLICIT  (MAPI_NEW_SESSION|MAPI_FORCE_DOWNLOAD|MAPI_EXPLICIT_PROFILE)

#define MAPI_INIT_VERSION  0

#define MAPI_MULTITHREAD_NOTIFICATIONS  0x00000001

#define MAPI_LOGOFF_SHARED  0x00000001
#define MAPI_LOGOFF_UI  0x00000002

#define MAPI_DEFAULT_STORE  0x00000001
#define MAPI_SIMPLE_STORE_TEMPORARY  0x00000002
#define MAPI_SIMPLE_STORE_PERMANENT  0x00000003
#define MAPI_PRIMARY_STORE  0x00000004
#define MAPI_SECONDARY_STORE  0x00000005

#define MAPI_POST_MESSAGE  0x00000001
#define MAPI_NEW_MESSAGE  0x00000002

#define MAPI_DEFAULT_SERVICES  0x00000001

#define SERVICE_DEFAULT_STORE  0x00000001
#define SERVICE_SINGLE_COPY  0x00000002
#define SERVICE_CREATE_WITH_STORE  0x00000004
#define SERVICE_PRIMARY_IDENTITY  0x00000008
#define SERVICE_NO_PRIMARY_IDENTITY  0x00000020

typedef struct {
    ULONG ulVersion;
    ULONG ulFlags;
} MAPIINIT_0, *LPMAPIINIT_0;

typedef MAPIINIT_0 MAPIINIT;
typedef MAPIINIT *LPMAPIINIT;

typedef HRESULT (STDAPICALLTYPE MAPIINITIALIZE)(LPVOID);
typedef MAPIINITIALIZE *LPMAPIINITIALIZE;

typedef void (STDAPICALLTYPE MAPIUNINITIALIZE)(void);
typedef MAPIUNINITIALIZE *LPMAPIUNINITIALIZE;

MAPIINITIALIZE  MAPIInitialize;
MAPIUNINITIALIZE  MAPIUninitialize;

typedef HRESULT (STDMETHODCALLTYPE MAPILOGONEX)(ULONG,LPTSTR,LPTSTR,ULONG,LPMAPISESSION*);
typedef MAPILOGONEX *LPMAPILOGONEX;

MAPILOGONEX MAPILogonEx;

typedef SCODE (STDMETHODCALLTYPE MAPIALLOCATEBUFFER)(ULONG,LPVOID*);
typedef SCODE (STDMETHODCALLTYPE MAPIALLOCATEMORE)(ULONG,LPVOID,LPVOID*);
typedef ULONG (STDAPICALLTYPE MAPIFREEBUFFER)(LPVOID);

typedef MAPIALLOCATEBUFFER *LPMAPIALLOCATEBUFFER;
typedef MAPIALLOCATEMORE *LPMAPIALLOCATEMORE;
typedef MAPIFREEBUFFER *LPMAPIFREEBUFFER;

MAPIALLOCATEBUFFER MAPIAllocateBuffer;
MAPIALLOCATEMORE MAPIAllocateMore;
MAPIFREEBUFFER MAPIFreeBuffer;

typedef HRESULT (STDMETHODCALLTYPE MAPIADMINPROFILES)(ULONG,LPPROFADMIN*);
typedef MAPIADMINPROFILES *LPMAPIADMINPROFILES;

MAPIADMINPROFILES MAPIAdminProfiles;

#define MAPI_IMAPISESSION_METHODS(IPURE)  \
    MAPIMETHOD(GetLastError)(THIS_ HRESULT,ULONG,LPMAPIERROR*) IPURE;  \
    MAPIMETHOD(GetMsgStoresTable)(THIS_ ULONG,LPMAPITABLE*) IPURE;  \
    MAPIMETHOD(OpenMsgStore)(THIS_ ULONG,ULONG,LPENTRYID,LPCIID,ULONG,LPMDB*) IPURE;  \
    MAPIMETHOD(OpenAddressBook)(THIS_ ULONG,LPCIID,ULONG,LPADRBOOK*) IPURE;  \
    MAPIMETHOD(OpenProfileSection)(THIS_ LPMAPIUID,LPCIID,ULONG,LPPROFSECT*) IPURE;  \
    MAPIMETHOD(GetStatusTable)(THIS_ ULONG,LPMAPITABLE*) IPURE;  \
    MAPIMETHOD(OpenEntry)(THIS_ ULONG,LPENTRYID,LPCIID,ULONG,ULONG*,LPUNKNOWN*) IPURE;  \
    MAPIMETHOD(CompareEntryIDs)(THIS_ ULONG,LPENTRYID,ULONG,LPENTRYID,ULONG,ULONG*) IPURE;  \
    MAPIMETHOD(Advise)(THIS_ ULONG,LPENTRYID,ULONG,LPMAPIADVISESINK,ULONG*) IPURE;  \
    MAPIMETHOD(Unadvise)(THIS_ ULONG) IPURE;  \
    MAPIMETHOD(MessageOptions)(THIS_ ULONG,ULONG,LPTSTR,LPMESSAGE) IPURE;  \
    MAPIMETHOD(QueryDefaultMessageOpt)(THIS_ LPTSTR,ULONG,ULONG*,LPSPropValue*) IPURE;  \
    MAPIMETHOD(EnumAdrTypes)(THIS_ ULONG,ULONG*,LPTSTR**) IPURE;  \
    MAPIMETHOD(QueryIdentity)(THIS_ ULONG*,LPENTRYID*) IPURE;  \
    MAPIMETHOD(Logoff)(THIS_ ULONG,ULONG,ULONG) IPURE;  \
    MAPIMETHOD(SetDefaultStore)(THIS_ ULONG,ULONG,LPENTRYID) IPURE;  \
    MAPIMETHOD(AdminServices)(THIS_ ULONG,LPSERVICEADMIN*) IPURE;  \
    MAPIMETHOD(ShowForm)(THIS_ ULONG,LPMDB,LPMAPIFOLDER,LPCIID,ULONG,LPMESSAGE,ULONG,ULONG,ULONG,ULONG,LPSTR) IPURE;  \
    MAPIMETHOD(PrepareForm)(THIS_ LPCIID,LPMESSAGE,ULONG*) IPURE;

#undef INTERFACE
#define INTERFACE IMAPISession
DECLARE_MAPI_INTERFACE_(IMAPISession,IUnknown)
{
    BEGIN_INTERFACE
    MAPI_IUNKNOWN_METHODS(PURE)
    MAPI_IMAPISESSION_METHODS(PURE)
};

#define MAPI_IADDRBOOK_METHODS(IPURE)  \
    MAPIMETHOD(OpenEntry)(THIS_ ULONG,LPENTRYID,LPCIID,ULONG,ULONG*,LPUNKNOWN*) IPURE;  \
    MAPIMETHOD(CompareEntryIDs)(THIS_ ULONG,LPENTRYID,ULONG,LPENTRYID,ULONG,ULONG*) IPURE;  \
    MAPIMETHOD(Advise)(THIS_ ULONG,LPENTRYID,ULONG,LPMAPIADVISESINK,ULONG*) IPURE;  \
    MAPIMETHOD(Unadvise)(THIS_ ULONG) IPURE;  \
    MAPIMETHOD(CreateOneOff)(THIS_ LPTSTR,LPTSTR,LPTSTR,ULONG,ULONG*,LPENTRYID*) IPURE;  \
    MAPIMETHOD(NewEntry)(THIS_ ULONG,ULONG,ULONG,LPENTRYID,ULONG,LPENTRYID,ULONG*,LPENTRYID*) IPURE;  \
    MAPIMETHOD(ResolveName)(THIS_ ULONG,ULONG,LPTSTR,LPADRLIST) IPURE;  \
    MAPIMETHOD(Address)(THIS_ ULONG*,LPADRPARM,LPADRLIST*) IPURE;  \
    MAPIMETHOD(Details)(THIS_ ULONG*,LPFNDISMISS,LPVOID,ULONG,LPENTRYID,LPFNBUTTON,LPVOID,LPTSTR,ULONG) IPURE;  \
    MAPIMETHOD(RecipOptions)(THIS_ ULONG,ULONG,LPADRENTRY) IPURE;  \
    MAPIMETHOD(QueryDefaultRecipOpt)(THIS_ LPTSTR,ULONG,ULONG*,LPSPropValue*) IPURE;  \
    MAPIMETHOD(GetPAB)(THIS_ ULONG*,LPENTRYID*) IPURE;  \
    MAPIMETHOD(SetPAB)(THIS_ ULONG,LPENTRYID) IPURE;  \
    MAPIMETHOD(GetDefaultDir)(THIS_ ULONG*,LPENTRYID*) IPURE;  \
    MAPIMETHOD(SetDefaultDir)(THIS_ ULONG,LPENTRYID) IPURE;  \
    MAPIMETHOD(GetSearchPath)(THIS_ ULONG,LPSRowSet*) IPURE;  \
    MAPIMETHOD(SetSearchPath)(THIS_ ULONG,LPSRowSet) IPURE;  \
    MAPIMETHOD(PrepareRecips)(THIS_ ULONG,LPSPropTagArray,LPADRLIST) IPURE;

#undef INTERFACE
#define INTERFACE IAddrBook
DECLARE_MAPI_INTERFACE_(IAddrBook,IMAPIProp)
{
    BEGIN_INTERFACE
    MAPI_IUNKNOWN_METHODS(PURE)
    MAPI_IMAPIPROP_METHODS(PURE)
    MAPI_IADDRBOOK_METHODS(PURE)
};

DECLARE_MAPI_INTERFACE_PTR(IAddrBook, LPADRBOOK);

#define MAPI_IPROFADMIN_METHODS(IPURE)  \
    MAPIMETHOD(GetLastError)(THIS_ HRESULT,ULONG,LPMAPIERROR*) IPURE;  \
    MAPIMETHOD(GetProfileTable)(THIS_ ULONG,LPMAPITABLE*) IPURE;  \
    MAPIMETHOD(CreateProfile)(THIS_ LPTSTR,LPTSTR,ULONG,ULONG) IPURE;  \
    MAPIMETHOD(DeleteProfile)(THIS_ LPTSTR,ULONG) IPURE;  \
    MAPIMETHOD(ChangeProfilePassword)(THIS_ LPTSTR,LPTSTR,LPTSTR,ULONG) IPURE;  \
    MAPIMETHOD(CopyProfile)(THIS_ LPTSTR,LPTSTR,LPTSTR,ULONG,ULONG) IPURE;  \
    MAPIMETHOD(RenameProfile)(THIS_ LPTSTR,LPTSTR,LPTSTR,ULONG,ULONG) IPURE;  \
    MAPIMETHOD(SetDefaultProfile)(THIS_ LPTSTR,ULONG) IPURE;  \
    MAPIMETHOD(AdminServices)(THIS_ LPTSTR,LPTSTR,ULONG,ULONG,LPSERVICEADMIN*) IPURE;

#undef INTERFACE
#define INTERFACE IProfAdmin
DECLARE_MAPI_INTERFACE_(IProfAdmin,IUnknown)
{
    BEGIN_INTERFACE
    MAPI_IUNKNOWN_METHODS(PURE)
    MAPI_IPROFADMIN_METHODS(PURE)
};

#define MAPI_IMSGSERVICEADMIN_METHODS(IPURE)  \
    MAPIMETHOD(GetLastError)(THIS_ HRESULT,ULONG,LPMAPIERROR*) IPURE;  \
    MAPIMETHOD(GetMsgServiceTable)(THIS_ ULONG,LPMAPITABLE*) IPURE;  \
    MAPIMETHOD(CreateMsgService)(THIS_ LPTSTR,LPTSTR,ULONG,ULONG) IPURE;  \
    MAPIMETHOD(DeleteMsgService)(THIS_ LPMAPIUID) IPURE;  \
    MAPIMETHOD(CopyMsgService)(THIS_ LPMAPIUID,LPTSTR,LPCIID,LPCIID,LPVOID,ULONG,ULONG) IPURE;  \
    MAPIMETHOD(RenameMsgService)(THIS_ LPMAPIUID,ULONG,LPTSTR) IPURE;  \
    MAPIMETHOD(ConfigureMsgService)(THIS_ LPMAPIUID,ULONG,ULONG,ULONG,LPSPropValue) IPURE;  \
    MAPIMETHOD(OpenProfileSection)(THIS_ LPMAPIUID,LPCIID,ULONG,LPPROFSECT*) IPURE;  \
    MAPIMETHOD(MsgServiceTransportOrder)(THIS_ ULONG,LPMAPIUID,ULONG) IPURE;  \
    MAPIMETHOD(AdminProviders)(THIS_ LPMAPIUID,ULONG,LPPROVIDERADMIN*) IPURE;  \
    MAPIMETHOD(SetPrimaryIdentity)(THIS_ LPMAPIUID,ULONG) IPURE;  \
    MAPIMETHOD(GetProviderTable)(THIS_ ULONG,LPMAPITABLE*) IPURE;

#undef INTERFACE
#define INTERFACE IMsgServiceAdmin
DECLARE_MAPI_INTERFACE_(IMsgServiceAdmin,IUnknown)
{
    BEGIN_INTERFACE
    MAPI_IUNKNOWN_METHODS(PURE)
    MAPI_IMSGSERVICEADMIN_METHODS(PURE)
};

#ifdef  __cplusplus
}
#endif

#endif /* _MAPIX_H */
