mapi32: Pass several extended MAPI functions through to provider.
[wine.git] / dlls / mapi32 / imalloc.c
blob351c38b6bb0c0de06bd73cf1e9ff1ba3d84c89a4
1 /*
2 * MAPI Default IMalloc implementation
4 * Copyright 2004 Jon Griffiths
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.
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.
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
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winuser.h"
30 #include "winerror.h"
31 #include "winternl.h"
32 #include "objbase.h"
33 #include "shlwapi.h"
34 #include "mapiutil.h"
35 #include "util.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mapi);
40 static const IMallocVtbl MAPI_IMalloc_vt;
42 typedef struct
44 const IMallocVtbl *lpVtbl;
45 LONG lRef;
46 } MAPI_IMALLOC;
48 static MAPI_IMALLOC MAPI_IMalloc = { &MAPI_IMalloc_vt, 0u };
50 extern LONG MAPI_ObjectCount; /* In mapi32_main.c */
52 /*************************************************************************
53 * MAPIGetDefaultMalloc@0 (MAPI32.59)
55 * Get the default MAPI IMalloc interface.
57 * PARAMS
58 * None.
60 * RETURNS
61 * A pointer to the MAPI default allocator.
63 LPMALLOC WINAPI MAPIGetDefaultMalloc(void)
65 TRACE("()\n");
67 if (mapiFunctions.MAPIGetDefaultMalloc)
68 return mapiFunctions.MAPIGetDefaultMalloc();
70 IMalloc_AddRef((LPMALLOC)&MAPI_IMalloc);
71 return (LPMALLOC)&MAPI_IMalloc;
74 /**************************************************************************
75 * IMAPIMalloc_QueryInterface
77 static HRESULT WINAPI IMAPIMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid,
78 LPVOID *ppvObj)
80 TRACE("(%s,%p)\n", debugstr_guid(refiid), ppvObj);
82 if (IsEqualIID(refiid, &IID_IUnknown) ||
83 IsEqualIID(refiid, &IID_IMalloc))
85 *ppvObj = &MAPI_IMalloc;
86 TRACE("Returning IMalloc (%p)\n", *ppvObj);
87 return S_OK;
89 TRACE("Returning E_NOINTERFACE\n");
90 return E_NOINTERFACE;
93 /**************************************************************************
94 * IMAPIMalloc_AddRef
96 static ULONG WINAPI IMAPIMalloc_fnAddRef(LPMALLOC iface)
98 TRACE("(%p)\n", iface);
99 InterlockedIncrement(&MAPI_ObjectCount);
100 return 1u;
103 /**************************************************************************
104 * IMAPIMalloc_Release
106 static ULONG WINAPI IMAPIMalloc_fnRelease(LPMALLOC iface)
108 TRACE("(%p)\n", iface);
109 InterlockedDecrement(&MAPI_ObjectCount);
110 return 1u;
113 /**************************************************************************
114 * IMAPIMalloc_Alloc
116 static LPVOID WINAPI IMAPIMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
118 TRACE("(%p)->(%d)\n", iface, cb);
120 return LocalAlloc(LMEM_FIXED, cb);
123 /**************************************************************************
124 * IMAPIMalloc_Realloc
126 static LPVOID WINAPI IMAPIMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
128 TRACE("(%p)->(%p, %d)\n", iface, pv, cb);
130 if (!pv)
131 return LocalAlloc(LMEM_FIXED, cb);
133 if (cb)
134 return LocalReAlloc(pv, cb, LMEM_MOVEABLE);
136 LocalFree(pv);
137 return NULL;
140 /**************************************************************************
141 * IMAPIMalloc_Free
143 static void WINAPI IMAPIMalloc_fnFree(LPMALLOC iface, LPVOID pv)
145 TRACE("(%p)->(%p)\n", iface, pv);
146 LocalFree(pv);
149 /**************************************************************************
150 * IMAPIMalloc_GetSize
152 static DWORD WINAPI IMAPIMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
154 TRACE("(%p)->(%p)\n", iface, pv);
155 return LocalSize(pv);
158 /**************************************************************************
159 * IMAPIMalloc_DidAlloc
161 static INT WINAPI IMAPIMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
163 TRACE("(%p)->(%p)\n", iface, pv);
164 return -1;
167 /**************************************************************************
168 * IMAPIMalloc_HeapMinimize
170 static void WINAPI IMAPIMalloc_fnHeapMinimize(LPMALLOC iface)
172 TRACE("(%p)\n", iface);
175 static const IMallocVtbl MAPI_IMalloc_vt =
177 IMAPIMalloc_fnQueryInterface,
178 IMAPIMalloc_fnAddRef,
179 IMAPIMalloc_fnRelease,
180 IMAPIMalloc_fnAlloc,
181 IMAPIMalloc_fnRealloc,
182 IMAPIMalloc_fnFree,
183 IMAPIMalloc_fnGetSize,
184 IMAPIMalloc_fnDidAlloc,
185 IMAPIMalloc_fnHeapMinimize