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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mapi
);
38 static const IMallocVtbl MAPI_IMalloc_vt
;
42 const IMallocVtbl
*lpVtbl
;
46 static MAPI_IMALLOC MAPI_IMalloc
= { &MAPI_IMalloc_vt
, 0u };
48 extern LONG MAPI_ObjectCount
; /* In mapi32_main.c */
50 /*************************************************************************
51 * MAPIGetDefaultMalloc@0 (MAPI32.59)
53 * Get the default MAPI IMalloc interface.
59 * A pointer to the MAPI default allocator.
61 LPMALLOC WINAPI
MAPIGetDefaultMalloc(void)
65 IMalloc_AddRef((LPMALLOC
)&MAPI_IMalloc
);
66 return (LPMALLOC
)&MAPI_IMalloc
;
69 /**************************************************************************
70 * IMAPIMalloc_QueryInterface
72 static HRESULT WINAPI
IMAPIMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
,
75 TRACE("(%s,%p)\n", debugstr_guid(refiid
), ppvObj
);
77 if (IsEqualIID(refiid
, &IID_IUnknown
) ||
78 IsEqualIID(refiid
, &IID_IMalloc
))
80 *ppvObj
= (LPMALLOC
) &MAPI_IMalloc
;
81 TRACE("Returning IMalloc (%p)\n", *ppvObj
);
84 TRACE("Returning E_NOINTERFACE\n");
88 /**************************************************************************
91 static ULONG WINAPI
IMAPIMalloc_fnAddRef(LPMALLOC iface
)
93 TRACE("(%p)\n", iface
);
94 InterlockedIncrement(&MAPI_ObjectCount
);
98 /**************************************************************************
101 static ULONG WINAPI
IMAPIMalloc_fnRelease(LPMALLOC iface
)
103 TRACE("(%p)\n", iface
);
104 InterlockedDecrement(&MAPI_ObjectCount
);
108 /**************************************************************************
111 static LPVOID WINAPI
IMAPIMalloc_fnAlloc(LPMALLOC iface
, DWORD cb
)
113 TRACE("(%p)->(%ld)\n", iface
, cb
);
115 return LocalAlloc(LMEM_FIXED
, cb
);
118 /**************************************************************************
119 * IMAPIMalloc_Realloc
121 static LPVOID WINAPI
IMAPIMalloc_fnRealloc(LPMALLOC iface
, LPVOID pv
, DWORD cb
)
123 TRACE("(%p)->(%p, %ld)\n", iface
, pv
, cb
);
126 return LocalAlloc(LMEM_FIXED
, cb
);
129 return LocalReAlloc((HANDLE
) pv
, cb
, LMEM_MOVEABLE
);
131 LocalFree((HANDLE
) pv
);
135 /**************************************************************************
138 static void WINAPI
IMAPIMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
140 TRACE("(%p)->(%p)\n", iface
, pv
);
141 LocalFree((HANDLE
) pv
);
144 /**************************************************************************
145 * IMAPIMalloc_GetSize
147 static DWORD WINAPI
IMAPIMalloc_fnGetSize(LPMALLOC iface
, LPVOID pv
)
149 TRACE("(%p)->(%p)\n", iface
, pv
);
150 return LocalSize((HANDLE
) pv
);
153 /**************************************************************************
154 * IMAPIMalloc_DidAlloc
156 static INT WINAPI
IMAPIMalloc_fnDidAlloc(LPMALLOC iface
, LPVOID pv
)
158 TRACE("(%p)->(%p)\n", iface
, pv
);
162 /**************************************************************************
163 * IMAPIMalloc_HeapMinimize
165 static void WINAPI
IMAPIMalloc_fnHeapMinimize(LPMALLOC iface
)
167 TRACE("(%p)\n", iface
);
170 static const IMallocVtbl MAPI_IMalloc_vt
=
172 IMAPIMalloc_fnQueryInterface
,
173 IMAPIMalloc_fnAddRef
,
174 IMAPIMalloc_fnRelease
,
176 IMAPIMalloc_fnRealloc
,
178 IMAPIMalloc_fnGetSize
,
179 IMAPIMalloc_fnDidAlloc
,
180 IMAPIMalloc_fnHeapMinimize