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 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
33 //#include "winuser.h"
34 //#include "winerror.h"
35 //#include "winternl.h"
36 //#include "objbase.h"
37 //#include "shlwapi.h"
40 #include <wine/debug.h>
42 WINE_DEFAULT_DEBUG_CHANNEL(mapi
);
44 static const IMallocVtbl MAPI_IMalloc_vt
;
48 const IMallocVtbl
*lpVtbl
;
52 static MAPI_IMALLOC MAPI_IMalloc
= { &MAPI_IMalloc_vt
, 0u };
54 extern LONG MAPI_ObjectCount
; /* In mapi32_main.c */
56 /*************************************************************************
57 * MAPIGetDefaultMalloc@0 (MAPI32.59)
59 * Get the default MAPI IMalloc interface.
65 * A pointer to the MAPI default allocator.
67 LPMALLOC WINAPI
MAPIGetDefaultMalloc(void)
71 if (mapiFunctions
.MAPIGetDefaultMalloc
)
72 return mapiFunctions
.MAPIGetDefaultMalloc();
74 IMalloc_AddRef((LPMALLOC
)&MAPI_IMalloc
);
75 return (LPMALLOC
)&MAPI_IMalloc
;
78 /**************************************************************************
79 * IMAPIMalloc_QueryInterface
81 static HRESULT WINAPI
IMAPIMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
,
84 TRACE("(%s,%p)\n", debugstr_guid(refiid
), ppvObj
);
86 if (IsEqualIID(refiid
, &IID_IUnknown
) ||
87 IsEqualIID(refiid
, &IID_IMalloc
))
89 *ppvObj
= &MAPI_IMalloc
;
90 TRACE("Returning IMalloc (%p)\n", *ppvObj
);
93 TRACE("Returning E_NOINTERFACE\n");
97 /**************************************************************************
100 static ULONG WINAPI
IMAPIMalloc_fnAddRef(LPMALLOC iface
)
102 TRACE("(%p)\n", iface
);
103 InterlockedIncrement(&MAPI_ObjectCount
);
107 /**************************************************************************
108 * IMAPIMalloc_Release
110 static ULONG WINAPI
IMAPIMalloc_fnRelease(LPMALLOC iface
)
112 TRACE("(%p)\n", iface
);
113 InterlockedDecrement(&MAPI_ObjectCount
);
117 /**************************************************************************
120 static LPVOID WINAPI
IMAPIMalloc_fnAlloc(LPMALLOC iface
, DWORD cb
)
122 TRACE("(%p)->(%d)\n", iface
, cb
);
124 return LocalAlloc(LMEM_FIXED
, cb
);
127 /**************************************************************************
128 * IMAPIMalloc_Realloc
130 static LPVOID WINAPI
IMAPIMalloc_fnRealloc(LPMALLOC iface
, LPVOID pv
, DWORD cb
)
132 TRACE("(%p)->(%p, %d)\n", iface
, pv
, cb
);
135 return LocalAlloc(LMEM_FIXED
, cb
);
138 return LocalReAlloc(pv
, cb
, LMEM_MOVEABLE
);
144 /**************************************************************************
147 static void WINAPI
IMAPIMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
149 TRACE("(%p)->(%p)\n", iface
, pv
);
153 /**************************************************************************
154 * IMAPIMalloc_GetSize
156 static DWORD WINAPI
IMAPIMalloc_fnGetSize(LPMALLOC iface
, LPVOID pv
)
158 TRACE("(%p)->(%p)\n", iface
, pv
);
159 return LocalSize(pv
);
162 /**************************************************************************
163 * IMAPIMalloc_DidAlloc
165 static INT WINAPI
IMAPIMalloc_fnDidAlloc(LPMALLOC iface
, LPVOID pv
)
167 TRACE("(%p)->(%p)\n", iface
, pv
);
171 /**************************************************************************
172 * IMAPIMalloc_HeapMinimize
174 static void WINAPI
IMAPIMalloc_fnHeapMinimize(LPMALLOC iface
)
176 TRACE("(%p)\n", iface
);
179 static const IMallocVtbl MAPI_IMalloc_vt
=
181 IMAPIMalloc_fnQueryInterface
,
182 IMAPIMalloc_fnAddRef
,
183 IMAPIMalloc_fnRelease
,
185 IMAPIMalloc_fnRealloc
,
187 IMAPIMalloc_fnGetSize
,
188 IMAPIMalloc_fnDidAlloc
,
189 IMAPIMalloc_fnHeapMinimize