ReactOS 0.4.15-dev-5863-g1fe3ab7
imalloc.c
Go to the documentation of this file.
1/*
2 * MAPI Default IMalloc implementation
3 *
4 * Copyright 2004 Jon Griffiths
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdarg.h>
22
23#define COBJMACROS
24
25#include "windef.h"
26#include "winbase.h"
27#include "winreg.h"
28#include "winuser.h"
29#include "winerror.h"
30#include "winternl.h"
31#include "objbase.h"
32#include "shlwapi.h"
33#include "mapiutil.h"
34#include "util.h"
35#include "wine/debug.h"
36
38
39static const IMallocVtbl MAPI_IMalloc_vt;
40
41typedef struct
42{
46
48
49extern LONG MAPI_ObjectCount; /* In mapi32_main.c */
50
51/*************************************************************************
52 * MAPIGetDefaultMalloc@0 (MAPI32.59)
53 *
54 * Get the default MAPI IMalloc interface.
55 *
56 * PARAMS
57 * None.
58 *
59 * RETURNS
60 * A pointer to the MAPI default allocator.
61 */
63{
64 TRACE("()\n");
65
66 if (mapiFunctions.MAPIGetDefaultMalloc)
67 return mapiFunctions.MAPIGetDefaultMalloc();
68
69 IMalloc_AddRef(&MAPI_IMalloc.IMalloc_iface);
71}
72
73/**************************************************************************
74 * IMAPIMalloc_QueryInterface
75 */
77 LPVOID *ppvObj)
78{
79 TRACE("(%s,%p)\n", debugstr_guid(refiid), ppvObj);
80
81 if (IsEqualIID(refiid, &IID_IUnknown) ||
82 IsEqualIID(refiid, &IID_IMalloc))
83 {
84 *ppvObj = &MAPI_IMalloc;
85 TRACE("Returning IMalloc (%p)\n", *ppvObj);
86 return S_OK;
87 }
88 TRACE("Returning E_NOINTERFACE\n");
89 return E_NOINTERFACE;
90}
91
92/**************************************************************************
93 * IMAPIMalloc_AddRef
94 */
96{
97 TRACE("(%p)\n", iface);
99 return 1u;
100}
101
102/**************************************************************************
103 * IMAPIMalloc_Release
104 */
106{
107 TRACE("(%p)\n", iface);
109 return 1u;
110}
111
112/**************************************************************************
113 * IMAPIMalloc_Alloc
114 */
116{
117 TRACE("(%p)->(%ld)\n", iface, cb);
118
119 return LocalAlloc(LMEM_FIXED, cb);
120}
121
122/**************************************************************************
123 * IMAPIMalloc_Realloc
124 */
126{
127 TRACE("(%p)->(%p, %ld)\n", iface, pv, cb);
128
129 if (!pv)
130 return LocalAlloc(LMEM_FIXED, cb);
131
132 if (cb)
133 return LocalReAlloc(pv, cb, LMEM_MOVEABLE);
134
135 LocalFree(pv);
136 return NULL;
137}
138
139/**************************************************************************
140 * IMAPIMalloc_Free
141 */
143{
144 TRACE("(%p)->(%p)\n", iface, pv);
145 LocalFree(pv);
146}
147
148/**************************************************************************
149 * IMAPIMalloc_GetSize
150 */
152{
153 TRACE("(%p)->(%p)\n", iface, pv);
154 return LocalSize(pv);
155}
156
157/**************************************************************************
158 * IMAPIMalloc_DidAlloc
159 */
161{
162 TRACE("(%p)->(%p)\n", iface, pv);
163 return -1;
164}
165
166/**************************************************************************
167 * IMAPIMalloc_HeapMinimize
168 */
170{
171 TRACE("(%p)\n", iface);
172}
173
174static const IMallocVtbl MAPI_IMalloc_vt =
175{
185};
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
const GUID IID_IUnknown
#define NULL
Definition: types.h:112
LPMALLOC WINAPI MAPIGetDefaultMalloc(void)
Definition: imalloc.c:62
static const IMallocVtbl MAPI_IMalloc_vt
Definition: imalloc.c:39
static SIZE_T WINAPI IMAPIMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
Definition: imalloc.c:151
static MAPI_IMALLOC MAPI_IMalloc
Definition: imalloc.c:47
static ULONG WINAPI IMAPIMalloc_fnAddRef(LPMALLOC iface)
Definition: imalloc.c:95
static HRESULT WINAPI IMAPIMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *ppvObj)
Definition: imalloc.c:76
static LPVOID WINAPI IMAPIMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, SIZE_T cb)
Definition: imalloc.c:125
static void WINAPI IMAPIMalloc_fnHeapMinimize(LPMALLOC iface)
Definition: imalloc.c:169
static ULONG WINAPI IMAPIMalloc_fnRelease(LPMALLOC iface)
Definition: imalloc.c:105
static LPVOID WINAPI IMAPIMalloc_fnAlloc(LPMALLOC iface, SIZE_T cb)
Definition: imalloc.c:115
static INT WINAPI IMAPIMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
Definition: imalloc.c:160
LONG MAPI_ObjectCount
Definition: mapi32_main.c:36
static void WINAPI IMAPIMalloc_fnFree(LPMALLOC iface, LPVOID pv)
Definition: imalloc.c:142
MAPI_FUNCTIONS mapiFunctions
Definition: util.c:49
HLOCAL NTAPI LocalReAlloc(HLOCAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:1608
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
SIZE_T NTAPI LocalSize(HLOCAL hMem)
Definition: heapmem.c:1777
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define S_OK
Definition: intsafe.h:52
#define debugstr_guid
Definition: kernel32.h:35
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
interface IMalloc * LPMALLOC
Definition: objfwd.h:12
long LONG
Definition: pedump.c:60
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define TRACE(s)
Definition: solgame.cpp:4
LONG lRef
Definition: imalloc.c:44
IMalloc IMalloc_iface
Definition: imalloc.c:43
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define LMEM_MOVEABLE
Definition: winbase.h:369
#define LMEM_FIXED
Definition: winbase.h:368
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364