ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

imalloc.c
Go to the documentation of this file.
00001 /*
00002  * MAPI Default IMalloc implementation
00003  *
00004  * Copyright 2004 Jon Griffiths
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <stdarg.h>
00022 
00023 #define COBJMACROS
00024 #define NONAMELESSUNION
00025 #define NONAMELESSSTRUCT
00026 #include "windef.h"
00027 #include "winbase.h"
00028 #include "winreg.h"
00029 #include "winuser.h"
00030 #include "winerror.h"
00031 #include "winternl.h"
00032 #include "objbase.h"
00033 #include "shlwapi.h"
00034 #include "mapiutil.h"
00035 #include "util.h"
00036 #include "wine/debug.h"
00037 
00038 WINE_DEFAULT_DEBUG_CHANNEL(mapi);
00039 
00040 static const IMallocVtbl MAPI_IMalloc_vt;
00041 
00042 typedef struct
00043 {
00044   const IMallocVtbl *lpVtbl;
00045   LONG lRef;
00046 } MAPI_IMALLOC;
00047 
00048 static MAPI_IMALLOC MAPI_IMalloc = { &MAPI_IMalloc_vt, 0u };
00049 
00050 extern LONG MAPI_ObjectCount; /* In mapi32_main.c */
00051 
00052 /*************************************************************************
00053  * MAPIGetDefaultMalloc@0 (MAPI32.59)
00054  *
00055  * Get the default MAPI IMalloc interface.
00056  *
00057  * PARAMS
00058  *  None.
00059  *
00060  * RETURNS
00061  *  A pointer to the MAPI default allocator.
00062  */
00063 LPMALLOC WINAPI MAPIGetDefaultMalloc(void)
00064 {
00065     TRACE("()\n");
00066 
00067     if (mapiFunctions.MAPIGetDefaultMalloc)
00068         return mapiFunctions.MAPIGetDefaultMalloc();
00069 
00070     IMalloc_AddRef((LPMALLOC)&MAPI_IMalloc);
00071     return (LPMALLOC)&MAPI_IMalloc;
00072 }
00073 
00074 /**************************************************************************
00075  * IMAPIMalloc_QueryInterface
00076  */
00077 static HRESULT WINAPI IMAPIMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid,
00078                                                    LPVOID *ppvObj)
00079 {
00080     TRACE("(%s,%p)\n", debugstr_guid(refiid), ppvObj);
00081 
00082     if (IsEqualIID(refiid, &IID_IUnknown) ||
00083         IsEqualIID(refiid, &IID_IMalloc))
00084     {
00085         *ppvObj = &MAPI_IMalloc;
00086         TRACE("Returning IMalloc (%p)\n", *ppvObj);
00087         return S_OK;
00088     }
00089     TRACE("Returning E_NOINTERFACE\n");
00090     return E_NOINTERFACE;
00091 }
00092 
00093 /**************************************************************************
00094  * IMAPIMalloc_AddRef
00095  */
00096 static ULONG WINAPI IMAPIMalloc_fnAddRef(LPMALLOC iface)
00097 {
00098     TRACE("(%p)\n", iface);
00099     InterlockedIncrement(&MAPI_ObjectCount);
00100     return 1u;
00101 }
00102 
00103 /**************************************************************************
00104  * IMAPIMalloc_Release
00105  */
00106 static ULONG WINAPI IMAPIMalloc_fnRelease(LPMALLOC iface)
00107 {
00108     TRACE("(%p)\n", iface);
00109     InterlockedDecrement(&MAPI_ObjectCount);
00110     return 1u;
00111 }
00112 
00113 /**************************************************************************
00114  * IMAPIMalloc_Alloc
00115  */
00116 static LPVOID WINAPI IMAPIMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
00117 {
00118     TRACE("(%p)->(%d)\n", iface, cb);
00119 
00120     return LocalAlloc(LMEM_FIXED, cb);
00121 }
00122 
00123 /**************************************************************************
00124  * IMAPIMalloc_Realloc
00125  */
00126 static LPVOID WINAPI IMAPIMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
00127 {
00128     TRACE("(%p)->(%p, %d)\n", iface, pv, cb);
00129 
00130     if (!pv)
00131         return LocalAlloc(LMEM_FIXED, cb);
00132 
00133     if (cb)
00134         return LocalReAlloc(pv, cb, LMEM_MOVEABLE);
00135 
00136     LocalFree(pv);
00137     return NULL;
00138 }
00139 
00140 /**************************************************************************
00141  * IMAPIMalloc_Free
00142  */
00143 static void WINAPI IMAPIMalloc_fnFree(LPMALLOC iface, LPVOID pv)
00144 {
00145     TRACE("(%p)->(%p)\n", iface, pv);
00146     LocalFree(pv);
00147 }
00148 
00149 /**************************************************************************
00150  * IMAPIMalloc_GetSize
00151  */
00152 static DWORD WINAPI IMAPIMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
00153 {
00154     TRACE("(%p)->(%p)\n", iface, pv);
00155     return LocalSize(pv);
00156 }
00157 
00158 /**************************************************************************
00159  * IMAPIMalloc_DidAlloc
00160  */
00161 static INT WINAPI IMAPIMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
00162 {
00163     TRACE("(%p)->(%p)\n", iface, pv);
00164     return -1;
00165 }
00166 
00167 /**************************************************************************
00168  * IMAPIMalloc_HeapMinimize
00169  */
00170 static void WINAPI IMAPIMalloc_fnHeapMinimize(LPMALLOC iface)
00171 {
00172     TRACE("(%p)\n", iface);
00173 }
00174 
00175 static const IMallocVtbl MAPI_IMalloc_vt =
00176 {
00177     IMAPIMalloc_fnQueryInterface,
00178     IMAPIMalloc_fnAddRef,
00179     IMAPIMalloc_fnRelease,
00180     IMAPIMalloc_fnAlloc,
00181     IMAPIMalloc_fnRealloc,
00182     IMAPIMalloc_fnFree,
00183     IMAPIMalloc_fnGetSize,
00184     IMAPIMalloc_fnDidAlloc,
00185     IMAPIMalloc_fnHeapMinimize
00186 };

Generated on Sun May 27 2012 04:24:37 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.