mapi32_main.c 8.11 KB
Newer Older
Aric Stewart's avatar
Aric Stewart committed
1 2 3
/*
 *             MAPI basics
 *
4
 * Copyright 2001, 2009 CodeWeavers Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Aric Stewart's avatar
Aric Stewart committed
19 20
 */

21 22
#include <stdarg.h>

Aric Stewart's avatar
Aric Stewart committed
23
#include "windef.h"
24
#include "winbase.h"
Aric Stewart's avatar
Aric Stewart committed
25
#include "winerror.h"
26
#include "objbase.h"
27
#include "initguid.h"
28
#include "mapix.h"
29
#include "mapiform.h"
30
#include "mapi.h"
31
#include "wine/debug.h"
32
#include "util.h"
Aric Stewart's avatar
Aric Stewart committed
33

34
WINE_DEFAULT_DEBUG_CHANNEL(mapi);
Aric Stewart's avatar
Aric Stewart committed
35

36 37
DECLSPEC_HIDDEN LONG MAPI_ObjectCount = 0;
DECLSPEC_HIDDEN HINSTANCE hInstMAPI32;
38 39 40 41 42 43

/***********************************************************************
 *              DllMain (MAPI32.init)
 */
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
{
44
    TRACE("(%p,%d,%p)\n", hinstDLL, fdwReason, fImpLoad);
45 46 47 48

    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
49
        hInstMAPI32 = hinstDLL;
50
        DisableThreadLibraryCalls(hinstDLL);
51
        load_mapi_providers();
52 53
        break;
    case DLL_PROCESS_DETACH:
54
        if (fImpLoad) break;
55
	TRACE("DLL_PROCESS_DETACH: %d objects remaining\n", MAPI_ObjectCount);
56
        unload_mapi_providers();
57 58 59 60 61
	break;
    }
    return TRUE;
}

62 63 64 65 66
/***********************************************************************
 *		DllGetClassObject (MAPI32.27)
 */
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
{
67 68 69 70 71 72 73 74
    if (mapiFunctions.DllGetClassObject)
    {
        HRESULT ret = mapiFunctions.DllGetClassObject(rclsid, iid, ppv);

        TRACE("ret: %x\n", ret);
        return ret;
    }

75
    FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
76 77

    *ppv = NULL;
78 79 80
    return CLASS_E_CLASSNOTAVAILABLE;
}

81 82 83 84 85 86 87 88 89 90 91 92
/***********************************************************************
 * DllCanUnloadNow (MAPI32.28)
 *
 * Determine if this dll can be unloaded from the callers address space.
 *
 * PARAMS
 *  None.
 *
 * RETURNS
 *  S_OK, if the dll can be unloaded,
 *  S_FALSE, otherwise.
 */
93
HRESULT WINAPI DllCanUnloadNow(void)
94
{
95 96 97 98 99 100 101 102 103
    HRESULT ret = S_OK;

    if (mapiFunctions.DllCanUnloadNow)
    {
        ret = mapiFunctions.DllCanUnloadNow();
        TRACE("(): provider returns %d\n", ret);
    }

    return MAPI_ObjectCount == 0 ? ret : S_FALSE;
104 105
}

106 107 108 109 110 111
/***********************************************************************
 * MAPIInitialize
 *
 * Initialises the MAPI library. In our case, we pass through to the
 * loaded Extended MAPI provider.
 */
112
HRESULT WINAPI MAPIInitialize(LPVOID init)
Aric Stewart's avatar
Aric Stewart committed
113
{
114 115 116 117 118 119
    TRACE("(%p)\n", init);

    if (mapiFunctions.MAPIInitialize)
        return mapiFunctions.MAPIInitialize(init);

    return MAPI_E_NOT_INITIALIZED;
Aric Stewart's avatar
Aric Stewart committed
120 121
}

122 123 124 125 126 127 128
/***********************************************************************
 * MAPILogon
 *
 * Logs on to a MAPI provider. If available, we pass this through to a
 * Simple MAPI provider. Otherwise, we maintain basic functionality
 * ourselves.
 */
129
ULONG WINAPI MAPILogon(ULONG_PTR uiparam, LPSTR profile, LPSTR password,
130
    FLAGS flags, ULONG reserved, LPLHANDLE session)
Aric Stewart's avatar
Aric Stewart committed
131
{
132
    TRACE("(0x%08Ix %s %p 0x%08x 0x%08x %p)\n", uiparam,
133 134
          debugstr_a(profile), password, flags, reserved, session);

135 136 137
    if (mapiFunctions.MAPILogon)
        return mapiFunctions.MAPILogon(uiparam, profile, password, flags, reserved, session);

138 139 140 141
    if (session) *session = 1;
    return SUCCESS_SUCCESS;
}

142 143 144 145 146 147 148
/***********************************************************************
 * MAPILogoff
 *
 * Logs off from a MAPI provider. If available, we pass this through to a
 * Simple MAPI provider. Otherwise, we maintain basic functionality
 * ourselves.
 */
149
ULONG WINAPI MAPILogoff(LHANDLE session, ULONG_PTR uiparam, FLAGS flags,
150 151
    ULONG reserved )
{
152
    TRACE("(0x%08Ix 0x%08Ix 0x%08x 0x%08x)\n", session,
153
          uiparam, flags, reserved);
154 155 156 157

    if (mapiFunctions.MAPILogoff)
        return mapiFunctions.MAPILogoff(session, uiparam, flags, reserved);

158
    return SUCCESS_SUCCESS;
Aric Stewart's avatar
Aric Stewart committed
159 160
}

161 162 163 164 165 166
/***********************************************************************
 * MAPILogonEx
 *
 * Logs on to a MAPI provider. If available, we pass this through to an
 * Extended MAPI provider. Otherwise, we return an error.
 */
167 168
HRESULT WINAPI MAPILogonEx(ULONG_PTR uiparam, LPWSTR profile,
    LPWSTR password, ULONG flags, LPMAPISESSION *session)
Aric Stewart's avatar
Aric Stewart committed
169
{
170
    TRACE("(0x%08Ix %s %p 0x%08x %p)\n", uiparam,
171
          debugstr_w(profile), password, flags, session);
172 173 174 175 176

    if (mapiFunctions.MAPILogonEx)
        return mapiFunctions.MAPILogonEx(uiparam, profile, password, flags, session);

    return E_FAIL;
Aric Stewart's avatar
Aric Stewart committed
177 178
}

179 180
HRESULT WINAPI MAPIOpenLocalFormContainer(LPVOID *ppfcnt)
{
181 182 183
    if (mapiFunctions.MAPIOpenLocalFormContainer)
        return mapiFunctions.MAPIOpenLocalFormContainer(ppfcnt);

184 185 186 187
    FIXME("(%p) Stub\n", ppfcnt);
    return E_FAIL;
}

188 189 190 191 192 193 194
/***********************************************************************
 * MAPIUninitialize
 *
 * Uninitialises the MAPI library. In our case, we pass through to the
 * loaded Extended MAPI provider.
 *
 */
195 196
VOID WINAPI MAPIUninitialize(void)
{
197 198 199 200 201
    TRACE("()\n");

    /* Try to uninitialise the Extended MAPI library */
    if (mapiFunctions.MAPIUninitialize)
        mapiFunctions.MAPIUninitialize();
202
}
203 204 205

HRESULT WINAPI MAPIAdminProfiles(ULONG ulFlags,  LPPROFADMIN *lppProfAdmin)
{
206 207 208
    if (mapiFunctions.MAPIAdminProfiles)
        return mapiFunctions.MAPIAdminProfiles(ulFlags, lppProfAdmin);

209 210 211 212
    FIXME("(%u, %p): stub\n", ulFlags, lppProfAdmin);
    *lppProfAdmin = NULL;
    return E_FAIL;
}
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

ULONG WINAPI MAPIAddress(LHANDLE session, ULONG_PTR uiparam, LPSTR caption,
    ULONG editfields, LPSTR labels, ULONG nRecips, lpMapiRecipDesc lpRecips,
    FLAGS flags, ULONG reserved, LPULONG newRecips, lpMapiRecipDesc * lppNewRecips)
{
    if (mapiFunctions.MAPIAddress)
        return mapiFunctions.MAPIAddress(session, uiparam, caption, editfields, labels,
            nRecips, lpRecips, flags, reserved, newRecips, lppNewRecips);

    return MAPI_E_NOT_SUPPORTED;
}

ULONG WINAPI MAPIDeleteMail(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_id,
    FLAGS flags, ULONG reserved)
{
    if (mapiFunctions.MAPIDeleteMail)
        return mapiFunctions.MAPIDeleteMail(session, uiparam, msg_id, flags, reserved);

    return MAPI_E_NOT_SUPPORTED;
}

ULONG WINAPI MAPIDetails(LHANDLE session, ULONG_PTR uiparam, lpMapiRecipDesc recip,
    FLAGS flags, ULONG reserved)
{
    if (mapiFunctions.MAPIDetails)
        return mapiFunctions.MAPIDetails(session, uiparam, recip, flags, reserved);

    return MAPI_E_NOT_SUPPORTED;
}

ULONG WINAPI MAPIFindNext(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_type,
    LPSTR seed_msg_id, FLAGS flags, ULONG reserved, LPSTR msg_id)
{
    if (mapiFunctions.MAPIFindNext)
        return mapiFunctions.MAPIFindNext(session, uiparam, msg_type, seed_msg_id, flags, reserved, msg_id);

    return MAPI_E_NOT_SUPPORTED;
}

ULONG WINAPI MAPIReadMail(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_id,
    FLAGS flags, ULONG reserved, lpMapiMessage msg)
{
    if (mapiFunctions.MAPIReadMail)
        return mapiFunctions.MAPIReadMail(session, uiparam, msg_id, flags, reserved, msg);

    return MAPI_E_NOT_SUPPORTED;
}

ULONG WINAPI MAPIResolveName(LHANDLE session, ULONG_PTR uiparam, LPSTR name,
    FLAGS flags, ULONG reserved, lpMapiRecipDesc *recip)
{
    if (mapiFunctions.MAPIResolveName)
        return mapiFunctions.MAPIResolveName(session, uiparam, name, flags, reserved, recip);

    return MAPI_E_NOT_SUPPORTED;
}

ULONG WINAPI MAPISaveMail(LHANDLE session, ULONG_PTR uiparam, lpMapiMessage msg,
    FLAGS flags, ULONG reserved, LPSTR msg_id)
{
    if (mapiFunctions.MAPISaveMail)
        return mapiFunctions.MAPISaveMail(session, uiparam, msg, flags, reserved, msg_id);

    return MAPI_E_NOT_SUPPORTED;
}