mapi32_main.c 8.05 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
LONG MAPI_ObjectCount = 0;
37
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
	TRACE("DLL_PROCESS_DETACH: %d objects remaining\n", MAPI_ObjectCount);
55
        unload_mapi_providers();
56 57 58 59 60
	break;
    }
    return TRUE;
}

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

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

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

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

80 81 82 83 84 85 86 87 88 89 90 91
/***********************************************************************
 * 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.
 */
92
HRESULT WINAPI DllCanUnloadNow(void)
93
{
94 95 96 97 98 99 100 101 102
    HRESULT ret = S_OK;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

208 209 210 211
    FIXME("(%u, %p): stub\n", ulFlags, lppProfAdmin);
    *lppProfAdmin = NULL;
    return E_FAIL;
}
212 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

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;
}