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
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mapi
);
40 static const IMallocVtbl MAPI_IMalloc_vt
;
44 IMalloc IMalloc_iface
;
48 static MAPI_IMALLOC MAPI_IMalloc
= { { &MAPI_IMalloc_vt
}, 0 };
50 extern LONG MAPI_ObjectCount
; /* In mapi32_main.c */
52 /*************************************************************************
53 * MAPIGetDefaultMalloc@0 (MAPI32.59)
55 * Get the default MAPI IMalloc interface.
61 * A pointer to the MAPI default allocator.
63 LPMALLOC WINAPI
MAPIGetDefaultMalloc(void)
67 if (mapiFunctions
.MAPIGetDefaultMalloc
)
68 return mapiFunctions
.MAPIGetDefaultMalloc();
70 IMalloc_AddRef(&MAPI_IMalloc
.IMalloc_iface
);
71 return &MAPI_IMalloc
.IMalloc_iface
;
74 /**************************************************************************
75 * IMAPIMalloc_QueryInterface
77 static HRESULT WINAPI
IMAPIMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
,
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
);
89 TRACE("Returning E_NOINTERFACE\n");
93 /**************************************************************************
96 static ULONG WINAPI
IMAPIMalloc_fnAddRef(LPMALLOC iface
)
98 TRACE("(%p)\n", iface
);
99 InterlockedIncrement(&MAPI_ObjectCount
);
103 /**************************************************************************
104 * IMAPIMalloc_Release
106 static ULONG WINAPI
IMAPIMalloc_fnRelease(LPMALLOC iface
)
108 TRACE("(%p)\n", iface
);
109 InterlockedDecrement(&MAPI_ObjectCount
);
113 /**************************************************************************
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
);
131 return LocalAlloc(LMEM_FIXED
, cb
);
134 return LocalReAlloc(pv
, cb
, LMEM_MOVEABLE
);
140 /**************************************************************************
143 static void WINAPI
IMAPIMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
145 TRACE("(%p)->(%p)\n", iface
, 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
);
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
,
181 IMAPIMalloc_fnRealloc
,
183 IMAPIMalloc_fnGetSize
,
184 IMAPIMalloc_fnDidAlloc
,
185 IMAPIMalloc_fnHeapMinimize