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