* Sync up to trunk head (r60691).
[reactos.git] / 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 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #include <stdarg.h>
26
27 #include <windef.h>
28 #include <winbase.h>
29 //#include "winerror.h"
30 //#include "objbase.h"
31 #include <initguid.h>
32 #include <mapix.h>
33 //#include "mapiform.h"
34 //#include "mapi.h"
35 #include <wine/debug.h>
36 #include "util.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(mapi);
39
40 DECLSPEC_HIDDEN LONG MAPI_ObjectCount = 0;
41 DECLSPEC_HIDDEN HINSTANCE hInstMAPI32;
42
43 /***********************************************************************
44 * DllMain (MAPI32.init)
45 */
46 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
47 {
48 TRACE("(%p,%d,%p)\n", hinstDLL, fdwReason, fImpLoad);
49
50 switch (fdwReason)
51 {
52 case DLL_PROCESS_ATTACH:
53 hInstMAPI32 = hinstDLL;
54 DisableThreadLibraryCalls(hinstDLL);
55 load_mapi_providers();
56 break;
57 case DLL_PROCESS_DETACH:
58 if (fImpLoad) break;
59 TRACE("DLL_PROCESS_DETACH: %d objects remaining\n", MAPI_ObjectCount);
60 unload_mapi_providers();
61 break;
62 }
63 return TRUE;
64 }
65
66 /***********************************************************************
67 * DllGetClassObject (MAPI32.27)
68 */
69 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
70 {
71 if (mapiFunctions.DllGetClassObject)
72 {
73 HRESULT ret = mapiFunctions.DllGetClassObject(rclsid, iid, ppv);
74
75 TRACE("ret: %x\n", ret);
76 return ret;
77 }
78
79 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
80
81 *ppv = NULL;
82 return CLASS_E_CLASSNOTAVAILABLE;
83 }
84
85 /***********************************************************************
86 * DllCanUnloadNow (MAPI32.28)
87 *
88 * Determine if this dll can be unloaded from the callers address space.
89 *
90 * PARAMS
91 * None.
92 *
93 * RETURNS
94 * S_OK, if the dll can be unloaded,
95 * S_FALSE, otherwise.
96 */
97 HRESULT WINAPI DllCanUnloadNow(void)
98 {
99 HRESULT ret = S_OK;
100
101 if (mapiFunctions.DllCanUnloadNow)
102 {
103 ret = mapiFunctions.DllCanUnloadNow();
104 TRACE("(): provider returns %d\n", ret);
105 }
106
107 return MAPI_ObjectCount == 0 ? ret : S_FALSE;
108 }
109
110 /***********************************************************************
111 * MAPIInitialize
112 *
113 * Initialises the MAPI library. In our case, we pass through to the
114 * loaded Extended MAPI provider.
115 */
116 HRESULT WINAPI MAPIInitialize(LPVOID init)
117 {
118 TRACE("(%p)\n", init);
119
120 if (mapiFunctions.MAPIInitialize)
121 return mapiFunctions.MAPIInitialize(init);
122
123 return MAPI_E_NOT_INITIALIZED;
124 }
125
126 /***********************************************************************
127 * MAPILogon
128 *
129 * Logs on to a MAPI provider. If available, we pass this through to a
130 * Simple MAPI provider. Otherwise, we maintain basic functionality
131 * ourselves.
132 */
133 ULONG WINAPI MAPILogon(ULONG_PTR uiparam, LPSTR profile, LPSTR password,
134 FLAGS flags, ULONG reserved, LPLHANDLE session)
135 {
136 TRACE("(0x%08lx %s %p 0x%08x 0x%08x %p)\n", uiparam,
137 debugstr_a(profile), password, flags, reserved, session);
138
139 if (mapiFunctions.MAPILogon)
140 return mapiFunctions.MAPILogon(uiparam, profile, password, flags, reserved, session);
141
142 if (session) *session = 1;
143 return SUCCESS_SUCCESS;
144 }
145
146 /***********************************************************************
147 * MAPILogoff
148 *
149 * Logs off from a MAPI provider. If available, we pass this through to a
150 * Simple MAPI provider. Otherwise, we maintain basic functionality
151 * ourselves.
152 */
153 ULONG WINAPI MAPILogoff(LHANDLE session, ULONG_PTR uiparam, FLAGS flags,
154 ULONG reserved )
155 {
156 TRACE("(0x%08lx 0x%08lx 0x%08x 0x%08x)\n", session,
157 uiparam, flags, reserved);
158
159 if (mapiFunctions.MAPILogoff)
160 return mapiFunctions.MAPILogoff(session, uiparam, flags, reserved);
161
162 return SUCCESS_SUCCESS;
163 }
164
165 /***********************************************************************
166 * MAPILogonEx
167 *
168 * Logs on to a MAPI provider. If available, we pass this through to an
169 * Extended MAPI provider. Otherwise, we return an error.
170 */
171 HRESULT WINAPI MAPILogonEx(ULONG_PTR uiparam, LPWSTR profile,
172 LPWSTR password, ULONG flags, LPMAPISESSION *session)
173 {
174 TRACE("(0x%08lx %s %p 0x%08x %p)\n", uiparam,
175 debugstr_w(profile), password, flags, session);
176
177 if (mapiFunctions.MAPILogonEx)
178 return mapiFunctions.MAPILogonEx(uiparam, profile, password, flags, session);
179
180 return E_FAIL;
181 }
182
183 HRESULT WINAPI MAPIOpenLocalFormContainer(LPVOID *ppfcnt)
184 {
185 if (mapiFunctions.MAPIOpenLocalFormContainer)
186 return mapiFunctions.MAPIOpenLocalFormContainer(ppfcnt);
187
188 FIXME("(%p) Stub\n", ppfcnt);
189 return E_FAIL;
190 }
191
192 /***********************************************************************
193 * MAPIUninitialize
194 *
195 * Uninitialises the MAPI library. In our case, we pass through to the
196 * loaded Extended MAPI provider.
197 *
198 */
199 VOID WINAPI MAPIUninitialize(void)
200 {
201 TRACE("()\n");
202
203 /* Try to uninitialise the Extended MAPI library */
204 if (mapiFunctions.MAPIUninitialize)
205 mapiFunctions.MAPIUninitialize();
206 }
207
208 HRESULT WINAPI MAPIAdminProfiles(ULONG ulFlags, LPPROFADMIN *lppProfAdmin)
209 {
210 if (mapiFunctions.MAPIAdminProfiles)
211 return mapiFunctions.MAPIAdminProfiles(ulFlags, lppProfAdmin);
212
213 FIXME("(%u, %p): stub\n", ulFlags, lppProfAdmin);
214 *lppProfAdmin = NULL;
215 return E_FAIL;
216 }
217
218 ULONG WINAPI MAPIAddress(LHANDLE session, ULONG_PTR uiparam, LPSTR caption,
219 ULONG editfields, LPSTR labels, ULONG nRecips, lpMapiRecipDesc lpRecips,
220 FLAGS flags, ULONG reserved, LPULONG newRecips, lpMapiRecipDesc * lppNewRecips)
221 {
222 if (mapiFunctions.MAPIAddress)
223 return mapiFunctions.MAPIAddress(session, uiparam, caption, editfields, labels,
224 nRecips, lpRecips, flags, reserved, newRecips, lppNewRecips);
225
226 return MAPI_E_NOT_SUPPORTED;
227 }
228
229 ULONG WINAPI MAPIDeleteMail(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_id,
230 FLAGS flags, ULONG reserved)
231 {
232 if (mapiFunctions.MAPIDeleteMail)
233 return mapiFunctions.MAPIDeleteMail(session, uiparam, msg_id, flags, reserved);
234
235 return MAPI_E_NOT_SUPPORTED;
236 }
237
238 ULONG WINAPI MAPIDetails(LHANDLE session, ULONG_PTR uiparam, lpMapiRecipDesc recip,
239 FLAGS flags, ULONG reserved)
240 {
241 if (mapiFunctions.MAPIDetails)
242 return mapiFunctions.MAPIDetails(session, uiparam, recip, flags, reserved);
243
244 return MAPI_E_NOT_SUPPORTED;
245 }
246
247 ULONG WINAPI MAPIFindNext(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_type,
248 LPSTR seed_msg_id, FLAGS flags, ULONG reserved, LPSTR msg_id)
249 {
250 if (mapiFunctions.MAPIFindNext)
251 return mapiFunctions.MAPIFindNext(session, uiparam, msg_type, seed_msg_id, flags, reserved, msg_id);
252
253 return MAPI_E_NOT_SUPPORTED;
254 }
255
256 ULONG WINAPI MAPIReadMail(LHANDLE session, ULONG_PTR uiparam, LPSTR msg_id,
257 FLAGS flags, ULONG reserved, lpMapiMessage msg)
258 {
259 if (mapiFunctions.MAPIReadMail)
260 return mapiFunctions.MAPIReadMail(session, uiparam, msg_id, flags, reserved, msg);
261
262 return MAPI_E_NOT_SUPPORTED;
263 }
264
265 ULONG WINAPI MAPIResolveName(LHANDLE session, ULONG_PTR uiparam, LPSTR name,
266 FLAGS flags, ULONG reserved, lpMapiRecipDesc *recip)
267 {
268 if (mapiFunctions.MAPIResolveName)
269 return mapiFunctions.MAPIResolveName(session, uiparam, name, flags, reserved, recip);
270
271 return MAPI_E_NOT_SUPPORTED;
272 }
273
274 ULONG WINAPI MAPISaveMail(LHANDLE session, ULONG_PTR uiparam, lpMapiMessage msg,
275 FLAGS flags, ULONG reserved, LPSTR msg_id)
276 {
277 if (mapiFunctions.MAPISaveMail)
278 return mapiFunctions.MAPISaveMail(session, uiparam, msg, flags, reserved, msg_id);
279
280 return MAPI_E_NOT_SUPPORTED;
281 }