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