home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / wincom / dllcom / src / dllmem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  1.8 KB  |  70 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. #include "dllcom.h"
  21. #include <assert.h>
  22.  
  23. // CoTaskMemAlloc uses the default OLE allocator to allocate a memory
  24. // block in the same way that IMalloc::Alloc does
  25. LPVOID
  26. CoTaskMemAlloc(ULONG cb)
  27. {
  28.     LPMALLOC pMalloc;
  29.      
  30.     if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
  31.         LPVOID    lpv = pMalloc->Alloc(cb);
  32.  
  33.         pMalloc->Release();
  34.         return lpv;
  35.     }
  36.  
  37.     return NULL;
  38. }
  39.  
  40. // CoTaskMemRealloc changes the size of a previously allocated memory
  41. // block in the same way that IMalloc::Realloc does
  42. LPVOID
  43. CoTaskMemRealloc(LPVOID lpv, ULONG cb)
  44. {
  45.     LPMALLOC    pMalloc;
  46.     
  47.     if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
  48.         lpv = pMalloc->Realloc(lpv, cb);
  49.         pMalloc->Release();
  50.         return lpv;
  51.     }
  52.  
  53.     return NULL;
  54. }
  55.  
  56. // CoTaskMemFree uses the default OLE allocator to free a block of
  57. // memory previously allocated through a call to CoTaskMemAlloc
  58. void
  59. CoTaskMemFree(LPVOID lpv)
  60. {
  61.     if (lpv) {
  62.         LPMALLOC    pMalloc;
  63.  
  64.         if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
  65.             pMalloc->Free(lpv);
  66.             pMalloc->Release();
  67.         }
  68.     }
  69. }
  70.