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
23 static const IMallocVtbl MAPI_IMalloc_vt
;
27 IMalloc IMalloc_iface
;
31 static MAPI_IMALLOC MAPI_IMalloc
= { { &MAPI_IMalloc_vt
}, 0 };
33 extern LONG MAPI_ObjectCount
; /* In mapi32_main.c */
35 /*************************************************************************
36 * MAPIGetDefaultMalloc@0 (MAPI32.59)
38 * Get the default MAPI IMalloc interface.
44 * A pointer to the MAPI default allocator.
46 LPMALLOC WINAPI
MAPIGetDefaultMalloc(void)
50 if (mapiFunctions
.MAPIGetDefaultMalloc
)
51 return mapiFunctions
.MAPIGetDefaultMalloc();
53 IMalloc_AddRef(&MAPI_IMalloc
.IMalloc_iface
);
54 return &MAPI_IMalloc
.IMalloc_iface
;
57 /**************************************************************************
58 * IMAPIMalloc_QueryInterface
60 static HRESULT WINAPI
IMAPIMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
,
63 TRACE("(%s,%p)\n", debugstr_guid(refiid
), ppvObj
);
65 if (IsEqualIID(refiid
, &IID_IUnknown
) ||
66 IsEqualIID(refiid
, &IID_IMalloc
))
68 *ppvObj
= &MAPI_IMalloc
;
69 TRACE("Returning IMalloc (%p)\n", *ppvObj
);
72 TRACE("Returning E_NOINTERFACE\n");
76 /**************************************************************************
79 static ULONG WINAPI
IMAPIMalloc_fnAddRef(LPMALLOC iface
)
81 TRACE("(%p)\n", iface
);
82 InterlockedIncrement(&MAPI_ObjectCount
);
86 /**************************************************************************
89 static ULONG WINAPI
IMAPIMalloc_fnRelease(LPMALLOC iface
)
91 TRACE("(%p)\n", iface
);
92 InterlockedDecrement(&MAPI_ObjectCount
);
96 /**************************************************************************
99 static LPVOID WINAPI
IMAPIMalloc_fnAlloc(LPMALLOC iface
, DWORD cb
)
101 TRACE("(%p)->(%d)\n", iface
, cb
);
103 return LocalAlloc(LMEM_FIXED
, cb
);
106 /**************************************************************************
107 * IMAPIMalloc_Realloc
109 static LPVOID WINAPI
IMAPIMalloc_fnRealloc(LPMALLOC iface
, LPVOID pv
, DWORD cb
)
111 TRACE("(%p)->(%p, %d)\n", iface
, pv
, cb
);
114 return LocalAlloc(LMEM_FIXED
, cb
);
117 return LocalReAlloc(pv
, cb
, LMEM_MOVEABLE
);
123 /**************************************************************************
126 static void WINAPI
IMAPIMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
128 TRACE("(%p)->(%p)\n", iface
, pv
);
132 /**************************************************************************
133 * IMAPIMalloc_GetSize
135 static DWORD WINAPI
IMAPIMalloc_fnGetSize(LPMALLOC iface
, LPVOID pv
)
137 TRACE("(%p)->(%p)\n", iface
, pv
);
138 return LocalSize(pv
);
141 /**************************************************************************
142 * IMAPIMalloc_DidAlloc
144 static INT WINAPI
IMAPIMalloc_fnDidAlloc(LPMALLOC iface
, LPVOID pv
)
146 TRACE("(%p)->(%p)\n", iface
, pv
);
150 /**************************************************************************
151 * IMAPIMalloc_HeapMinimize
153 static void WINAPI
IMAPIMalloc_fnHeapMinimize(LPMALLOC iface
)
155 TRACE("(%p)\n", iface
);
158 static const IMallocVtbl MAPI_IMalloc_vt
=
160 IMAPIMalloc_fnQueryInterface
,
161 IMAPIMalloc_fnAddRef
,
162 IMAPIMalloc_fnRelease
,
164 IMAPIMalloc_fnRealloc
,
166 IMAPIMalloc_fnGetSize
,
167 IMAPIMalloc_fnDidAlloc
,
168 IMAPIMalloc_fnHeapMinimize