28c2f140d9cfb7eb7d40e379ec369ec105f936e0
[reactos.git] / reactos / dll / win32 / mapi32 / mapi32_main.c
1 /*
2 * MAPI basics
3 *
4 * Copyright 2001, 2009 CodeWeavers Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * 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
19 */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
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"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mapi);
35
36 LONG MAPI_ObjectCount = 0;
37
38 /***********************************************************************
39 * DllMain (MAPI32.init)
40 */
41 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
42 {
43 TRACE("(%p,%d,%p)\n", hinstDLL, fdwReason, fImpLoad);
44
45 switch (fdwReason)
46 {
47 case DLL_PROCESS_ATTACH:
48 DisableThreadLibraryCalls(hinstDLL);
49 load_mapi_providers();
50 break;
51 case DLL_PROCESS_DETACH:
52 TRACE("DLL_PROCESS_DETACH: %d objects remaining\n", MAPI_ObjectCount);
53 unload_mapi_providers();
54 break;
55 }
56 return TRUE;
57 }
58
59 /***********************************************************************
60 * DllGetClassObject (MAPI32.27)
61 */
62 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
63 {
64 if (mapiFunctions.DllGetClassObject)
65 {
66 HRESULT ret = mapiFunctions.DllGetClassObject(rclsid, iid, ppv);
67
68 TRACE("ret: %x\n", ret);
69 return ret;
70 }
71
72 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
73
74 *ppv = NULL;
75 return CLASS_E_CLASSNOTAVAILABLE;
76 }
77
78 /***********************************************************************
79 * DllCanUnloadNow (MAPI32.28)
80 *
81 * Determine if this dll can be unloaded from the callers address space.
82 *
83 * PARAMS
84 * None.
85 *
86 * RETURNS
87 * S_OK, if the dll can be unloaded,
88 * S_FALSE, otherwise.
89 */
90 HRESULT WINAPI DllCanUnloadNow(void)
91 {
92 return MAPI_ObjectCount == 0 ? S_OK : S_FALSE;
93 }
94
95 /***********************************************************************
96 * MAPIInitialize
97 *
98 * Initialises the MAPI library. In our case, we pass through to the
99 * loaded Extended MAPI provider.
100 */
101 HRESULT WINAPI MAPIInitialize(LPVOID init)
102 {
103 TRACE("(%p)\n", init);
104
105 if (mapiFunctions.MAPIInitialize)
106 return mapiFunctions.MAPIInitialize(init);
107
108 return MAPI_E_NOT_INITIALIZED;
109 }
110
111 /***********************************************************************
112 * MAPILogon
113 *
114 * Logs on to a MAPI provider. If available, we pass this through to a
115 * Simple MAPI provider. Otherwise, we maintain basic functionality
116 * ourselves.
117 */
118 ULONG WINAPI MAPILogon(ULONG_PTR uiparam, LPSTR profile, LPSTR password,
119 FLAGS flags, ULONG reserved, LPLHANDLE session)
120 {
121 TRACE("(0x%08lx %s %p 0x%08x 0x%08x %p)\n", uiparam,
122 debugstr_a(profile), password, flags, reserved, session);
123
124 if (mapiFunctions.MAPILogon)
125 return mapiFunctions.MAPILogon(uiparam, profile, password, flags, reserved, session);
126
127 if (session) *session = 1;
128 return SUCCESS_SUCCESS;
129 }
130
131 /***********************************************************************
132 * MAPILogoff
133 *
134 * Logs off from a MAPI provider. If available, we pass this through to a
135 * Simple MAPI provider. Otherwise, we maintain basic functionality
136 * ourselves.
137 */
138 ULONG WINAPI MAPILogoff(LHANDLE session, ULONG_PTR uiparam, FLAGS flags,
139 ULONG reserved )
140 {
141 TRACE("(0x%08lx 0x%08lx 0x%08x 0x%08x)\n", session,
142 uiparam, flags, reserved);
143
144 if (mapiFunctions.MAPILogoff)
145 return mapiFunctions.MAPILogoff(session, uiparam, flags, reserved);
146
147 return SUCCESS_SUCCESS;
148 }
149
150 /***********************************************************************
151 * MAPILogonEx
152 *
153 * Logs on to a MAPI provider. If available, we pass this through to an
154 * Extended MAPI provider. Otherwise, we return an error.
155 */
156 HRESULT WINAPI MAPILogonEx(ULONG_PTR uiparam, LPWSTR profile,
157 LPWSTR password, ULONG flags, LPMAPISESSION *session)
158 {
159 TRACE("(0x%08lx %s %p 0x%08x %p)\n", uiparam,
160 debugstr_w(profile), password, flags, session);
161
162 if (mapiFunctions.MAPILogonEx)
163 return mapiFunctions.MAPILogonEx(uiparam, profile, password, flags, session);
164
165 return E_FAIL;
166 }
167
168 HRESULT WINAPI MAPIOpenLocalFormContainer(LPVOID *ppfcnt)
169 {
170 FIXME("(%p) Stub\n", ppfcnt);
171 return E_FAIL;
172 }
173
174 /***********************************************************************
175 * MAPIUninitialize
176 *
177 * Uninitialises the MAPI library. In our case, we pass through to the
178 * loaded Extended MAPI provider.
179 *
180 */
181 VOID WINAPI MAPIUninitialize(void)
182 {
183 TRACE("()\n");
184
185 /* Try to uninitialise the Extended MAPI library */
186 if (mapiFunctions.MAPIUninitialize)
187 mapiFunctions.MAPIUninitialize();
188 }
189
190 HRESULT WINAPI MAPIAdminProfiles(ULONG ulFlags, LPPROFADMIN *lppProfAdmin)
191 {
192 FIXME("(%u, %p): stub\n", ulFlags, lppProfAdmin);
193 *lppProfAdmin = NULL;
194 return E_FAIL;
195 }
196
197 ULONG WINAPI MAPIAddress(LHANDLE session, ULONG_PTR uiparam, LPSTR caption,
198 ULONG editfields, LPSTR labels, ULONG nRecips, lpMapiRecipDesc lpRecips,
199 FLAGS flags, ULONG reserved, LPULONG newRecips, lpMapiRecipDesc * lppNewRecips)
200 {
201 if (mapiFunctions.MAPIAddress)
202 return mapiFunctions.MAPIAddress(session, uiparam, caption, editfields, labels,
203 nRecips, lpRecips, flags, reserved, newRecips, lppNewRecips);
204
205 return MAPI_E_NOT_SUPPORTED;
206 }
207
208 ULONG WINAPI MAPIDeleteMail(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_id,
209 FLAGS flags, ULONG reserved)
210 {
211 if (mapiFunctions.MAPIDeleteMail)
212 return mapiFunctions.MAPIDeleteMail(session, uiparam, msg_id, flags, reserved);
213
214 return MAPI_E_NOT_SUPPORTED;
215 }
216
217 ULONG WINAPI MAPIDetails(LHANDLE session, ULONG_PTR uiparam, lpMapiRecipDesc recip,
218 FLAGS flags, ULONG reserved)
219 {
220 if (mapiFunctions.MAPIDetails)
221 return mapiFunctions.MAPIDetails(session, uiparam, recip, flags, reserved);
222
223 return MAPI_E_NOT_SUPPORTED;
224 }
225
226 ULONG WINAPI MAPIFindNext(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_type,
227 LPSTR seed_msg_id, FLAGS flags, ULONG reserved, LPSTR msg_id)
228 {
229 if (mapiFunctions.MAPIFindNext)
230 return mapiFunctions.MAPIFindNext(session, uiparam, msg_type, seed_msg_id, flags, reserved, msg_id);
231
232 return MAPI_E_NOT_SUPPORTED;
233 }
234
235 ULONG WINAPI MAPIReadMail(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_id,
236 FLAGS flags, ULONG reserved, lpMapiMessage msg)
237 {
238 if (mapiFunctions.MAPIReadMail)
239 return mapiFunctions.MAPIReadMail(session, uiparam, msg_id, flags, reserved, msg);
240
241 return MAPI_E_NOT_SUPPORTED;
242 }
243
244 ULONG WINAPI MAPIResolveName(LHANDLE session, ULONG_PTR uiparam, LPSTR name,
245 FLAGS flags, ULONG reserved, lpMapiRecipDesc *recip)
246 {
247 if (mapiFunctions.MAPIResolveName)
248 return mapiFunctions.MAPIResolveName(session, uiparam, name, flags, reserved, recip);
249
250 return MAPI_E_NOT_SUPPORTED;
251 }
252
253 ULONG WINAPI MAPISaveMail(LHANDLE session, ULONG_PTR uiparam, lpMapiMessage msg,
254 FLAGS flags, ULONG reserved, LPSTR msg_id)
255 {
256 if (mapiFunctions.MAPISaveMail)
257 return mapiFunctions.MAPISaveMail(session, uiparam, msg, flags, reserved, msg_id);
258
259 return MAPI_E_NOT_SUPPORTED;
260 }