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
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mapi
);
39 static const IMallocVtbl MAPI_IMalloc_vt
;
43 IMalloc IMalloc_iface
;
47 static MAPI_IMALLOC MAPI_IMalloc
= { { &MAPI_IMalloc_vt
}, 0 };
49 extern LONG MAPI_ObjectCount
; /* In mapi32_main.c */
51 /*************************************************************************
52 * MAPIGetDefaultMalloc@0 (MAPI32.59)
54 * Get the default MAPI IMalloc interface.
60 * A pointer to the MAPI default allocator.
62 LPMALLOC WINAPI
MAPIGetDefaultMalloc(void)
66 if (mapiFunctions
.MAPIGetDefaultMalloc
)
67 return mapiFunctions
.MAPIGetDefaultMalloc();
69 IMalloc_AddRef(&MAPI_IMalloc
.IMalloc_iface
);
70 return &MAPI_IMalloc
.IMalloc_iface
;
73 /**************************************************************************
74 * IMAPIMalloc_QueryInterface
76 static HRESULT WINAPI
IMAPIMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
,
79 TRACE("(%s,%p)\n", debugstr_guid(refiid
), ppvObj
);
81 if (IsEqualIID(refiid
, &IID_IUnknown
) ||
82 IsEqualIID(refiid
, &IID_IMalloc
))
84 *ppvObj
= &MAPI_IMalloc
;
85 TRACE("Returning IMalloc (%p)\n", *ppvObj
);
88 TRACE("Returning E_NOINTERFACE\n");
92 /**************************************************************************
95 static ULONG WINAPI
IMAPIMalloc_fnAddRef(LPMALLOC iface
)
97 TRACE("(%p)\n", iface
);
98 InterlockedIncrement(&MAPI_ObjectCount
);
102 /**************************************************************************
103 * IMAPIMalloc_Release
105 static ULONG WINAPI
IMAPIMalloc_fnRelease(LPMALLOC iface
)
107 TRACE("(%p)\n", iface
);
108 InterlockedDecrement(&MAPI_ObjectCount
);
112 /**************************************************************************
115 static LPVOID WINAPI
IMAPIMalloc_fnAlloc(LPMALLOC iface
, DWORD cb
)
117 TRACE("(%p)->(%d)\n", iface
, cb
);
119 return LocalAlloc(LMEM_FIXED
, cb
);
122 /**************************************************************************
123 * IMAPIMalloc_Realloc
125 static LPVOID WINAPI
IMAPIMalloc_fnRealloc(LPMALLOC iface
, LPVOID pv
, DWORD cb
)
127 TRACE("(%p)->(%p, %d)\n", iface
, pv
, cb
);
130 return LocalAlloc(LMEM_FIXED
, cb
);
133 return LocalReAlloc(pv
, cb
, LMEM_MOVEABLE
);
139 /**************************************************************************
142 static void WINAPI
IMAPIMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
144 TRACE("(%p)->(%p)\n", iface
, pv
);
148 /**************************************************************************
149 * IMAPIMalloc_GetSize
151 static DWORD WINAPI
IMAPIMalloc_fnGetSize(LPMALLOC iface
, LPVOID pv
)
153 TRACE("(%p)->(%p)\n", iface
, pv
);
154 return LocalSize(pv
);
157 /**************************************************************************
158 * IMAPIMalloc_DidAlloc
160 static INT WINAPI
IMAPIMalloc_fnDidAlloc(LPMALLOC iface
, LPVOID pv
)
162 TRACE("(%p)->(%p)\n", iface
, pv
);
166 /**************************************************************************
167 * IMAPIMalloc_HeapMinimize
169 static void WINAPI
IMAPIMalloc_fnHeapMinimize(LPMALLOC iface
)
171 TRACE("(%p)\n", iface
);
174 static const IMallocVtbl MAPI_IMalloc_vt
=
176 IMAPIMalloc_fnQueryInterface
,
177 IMAPIMalloc_fnAddRef
,
178 IMAPIMalloc_fnRelease
,
180 IMAPIMalloc_fnRealloc
,
182 IMAPIMalloc_fnGetSize
,
183 IMAPIMalloc_fnDidAlloc
,
184 IMAPIMalloc_fnHeapMinimize