ReactOS  0.4.15-dev-1206-g731eddf
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 
39 static const IMallocVtbl MAPI_IMalloc_vt;
40 
41 typedef struct
42 {
45 } MAPI_IMALLOC;
46 
48 
49 extern 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  */
142 static void WINAPI IMAPIMalloc_fnFree(LPMALLOC iface, LPVOID pv)
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 
174 static const IMallocVtbl MAPI_IMalloc_vt =
175 {
185 };
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
interface IMalloc * LPMALLOC
Definition: objfwd.h:12
static SIZE_T WINAPI IMAPIMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
Definition: imalloc.c:151
SIZE_T NTAPI LocalSize(HLOCAL hMem)
Definition: heapmem.c:1777
int32_t INT
Definition: typedefs.h:58
LONG MAPI_ObjectCount
Definition: mapi32_main.c:36
static INT WINAPI IMAPIMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
Definition: imalloc.c:160
static ULONG WINAPI IMAPIMalloc_fnAddRef(LPMALLOC iface)
Definition: imalloc.c:95
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
#define LMEM_FIXED
Definition: winbase.h:349
#define TRACE(s)
Definition: solgame.cpp:4
static ULONG WINAPI IMAPIMalloc_fnRelease(LPMALLOC iface)
Definition: imalloc.c:105
LONG HRESULT
Definition: typedefs.h:79
static void WINAPI IMAPIMalloc_fnHeapMinimize(LPMALLOC iface)
Definition: imalloc.c:169
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:6
#define LMEM_MOVEABLE
Definition: winbase.h:350
static MAPI_IMALLOC MAPI_IMalloc
Definition: imalloc.c:47
static void WINAPI IMAPIMalloc_fnFree(LPMALLOC iface, LPVOID pv)
Definition: imalloc.c:142
#define InterlockedDecrement
Definition: armddk.h:52
MAPI_FUNCTIONS mapiFunctions
Definition: util.c:49
static LPVOID WINAPI IMAPIMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, SIZE_T cb)
Definition: imalloc.c:125
static const IMallocVtbl MAPI_IMalloc_vt
Definition: imalloc.c:39
IMalloc IMalloc_iface
Definition: imalloc.c:43
WINE_DEFAULT_DEBUG_CHANNEL(mapi)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define S_OK
Definition: intsafe.h:51
#define InterlockedIncrement
Definition: armddk.h:53
HLOCAL NTAPI LocalReAlloc(HLOCAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:1608
static LPVOID WINAPI IMAPIMalloc_fnAlloc(LPMALLOC iface, SIZE_T cb)
Definition: imalloc.c:115
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static HRESULT WINAPI IMAPIMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *ppvObj)
Definition: imalloc.c:76
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
unsigned int ULONG
Definition: retypes.h:1
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
LPMALLOC WINAPI MAPIGetDefaultMalloc(void)
Definition: imalloc.c:62
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
LONG lRef
Definition: imalloc.c:44