[SHELL32] CDrivesFolder: Implement the eject and disconnect menu items. CORE-13841
[reactos.git] / dll / win32 / mapi32 / imalloc.c
1 /*
2 * MAPI Default IMalloc implementation
3 *
4 * Copyright 2004 Jon Griffiths
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 static const IMallocVtbl MAPI_IMalloc_vt;
24
25 typedef struct
26 {
27 IMalloc IMalloc_iface;
28 LONG lRef;
29 } MAPI_IMALLOC;
30
31 static MAPI_IMALLOC MAPI_IMalloc = { { &MAPI_IMalloc_vt }, 0 };
32
33 extern LONG MAPI_ObjectCount; /* In mapi32_main.c */
34
35 /*************************************************************************
36 * MAPIGetDefaultMalloc@0 (MAPI32.59)
37 *
38 * Get the default MAPI IMalloc interface.
39 *
40 * PARAMS
41 * None.
42 *
43 * RETURNS
44 * A pointer to the MAPI default allocator.
45 */
46 LPMALLOC WINAPI MAPIGetDefaultMalloc(void)
47 {
48 TRACE("()\n");
49
50 if (mapiFunctions.MAPIGetDefaultMalloc)
51 return mapiFunctions.MAPIGetDefaultMalloc();
52
53 IMalloc_AddRef(&MAPI_IMalloc.IMalloc_iface);
54 return &MAPI_IMalloc.IMalloc_iface;
55 }
56
57 /**************************************************************************
58 * IMAPIMalloc_QueryInterface
59 */
60 static HRESULT WINAPI IMAPIMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid,
61 LPVOID *ppvObj)
62 {
63 TRACE("(%s,%p)\n", debugstr_guid(refiid), ppvObj);
64
65 if (IsEqualIID(refiid, &IID_IUnknown) ||
66 IsEqualIID(refiid, &IID_IMalloc))
67 {
68 *ppvObj = &MAPI_IMalloc;
69 TRACE("Returning IMalloc (%p)\n", *ppvObj);
70 return S_OK;
71 }
72 TRACE("Returning E_NOINTERFACE\n");
73 return E_NOINTERFACE;
74 }
75
76 /**************************************************************************
77 * IMAPIMalloc_AddRef
78 */
79 static ULONG WINAPI IMAPIMalloc_fnAddRef(LPMALLOC iface)
80 {
81 TRACE("(%p)\n", iface);
82 InterlockedIncrement(&MAPI_ObjectCount);
83 return 1u;
84 }
85
86 /**************************************************************************
87 * IMAPIMalloc_Release
88 */
89 static ULONG WINAPI IMAPIMalloc_fnRelease(LPMALLOC iface)
90 {
91 TRACE("(%p)\n", iface);
92 InterlockedDecrement(&MAPI_ObjectCount);
93 return 1u;
94 }
95
96 /**************************************************************************
97 * IMAPIMalloc_Alloc
98 */
99 static LPVOID WINAPI IMAPIMalloc_fnAlloc(LPMALLOC iface, SIZE_T cb)
100 {
101 TRACE("(%p)->(%ld)\n", iface, cb);
102
103 return LocalAlloc(LMEM_FIXED, cb);
104 }
105
106 /**************************************************************************
107 * IMAPIMalloc_Realloc
108 */
109 static LPVOID WINAPI IMAPIMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, SIZE_T cb)
110 {
111 TRACE("(%p)->(%p, %ld)\n", iface, pv, cb);
112
113 if (!pv)
114 return LocalAlloc(LMEM_FIXED, cb);
115
116 if (cb)
117 return LocalReAlloc(pv, cb, LMEM_MOVEABLE);
118
119 LocalFree(pv);
120 return NULL;
121 }
122
123 /**************************************************************************
124 * IMAPIMalloc_Free
125 */
126 static void WINAPI IMAPIMalloc_fnFree(LPMALLOC iface, LPVOID pv)
127 {
128 TRACE("(%p)->(%p)\n", iface, pv);
129 LocalFree(pv);
130 }
131
132 /**************************************************************************
133 * IMAPIMalloc_GetSize
134 */
135 static SIZE_T WINAPI IMAPIMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
136 {
137 TRACE("(%p)->(%p)\n", iface, pv);
138 return LocalSize(pv);
139 }
140
141 /**************************************************************************
142 * IMAPIMalloc_DidAlloc
143 */
144 static INT WINAPI IMAPIMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
145 {
146 TRACE("(%p)->(%p)\n", iface, pv);
147 return -1;
148 }
149
150 /**************************************************************************
151 * IMAPIMalloc_HeapMinimize
152 */
153 static void WINAPI IMAPIMalloc_fnHeapMinimize(LPMALLOC iface)
154 {
155 TRACE("(%p)\n", iface);
156 }
157
158 static const IMallocVtbl MAPI_IMalloc_vt =
159 {
160 IMAPIMalloc_fnQueryInterface,
161 IMAPIMalloc_fnAddRef,
162 IMAPIMalloc_fnRelease,
163 IMAPIMalloc_fnAlloc,
164 IMAPIMalloc_fnRealloc,
165 IMAPIMalloc_fnFree,
166 IMAPIMalloc_fnGetSize,
167 IMAPIMalloc_fnDidAlloc,
168 IMAPIMalloc_fnHeapMinimize
169 };