home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / interfac / imalloc.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  209 lines

  1. /*
  2.  * IMALLOC.CPP
  3.  *
  4.  * Template IMalloc interface implementation.
  5.  *
  6.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Microsoft
  9.  * Internet  :  kraigb@microsoft.com
  10.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  11.  */
  12.  
  13.  
  14. #include "imalloc.h"
  15.  
  16.  
  17. /*
  18.  * CImpIMalloc::CImpIMalloc
  19.  * CImpIMalloc::~CImpIMalloc
  20.  *
  21.  * Parameters (Constructor):
  22.  *  pObj            LPVOID of the object we're in.
  23.  *  pUnkOuter       LPUNKNOWN to which we delegate.
  24.  */
  25.  
  26. CImpIMalloc::CImpIMalloc(LPVOID pObj, LPUNKNOWN pUnkOuter)
  27.     {
  28.     m_cRef=0;
  29.     m_pObj=pObj;
  30.     m_pUnkOuter=pUnkOuter;
  31.     return;
  32.     }
  33.  
  34. CImpIMalloc::~CImpIMalloc(void)
  35.     {
  36.     return;
  37.     }
  38.  
  39.  
  40.  
  41. /*
  42.  * CImpIMalloc::QueryInterface
  43.  * CImpIMalloc::AddRef
  44.  * CImpIMalloc::Release
  45.  *
  46.  * Purpose:
  47.  *  Delegating IUnknown members for CImpIMalloc.
  48.  */
  49.  
  50. STDMETHODIMP CImpIMalloc::QueryInterface(REFIID riid
  51.     , LPVOID *ppv)
  52.     {
  53.     return m_pUnkOuter->QueryInterface(riid, ppv);
  54.     }
  55.  
  56. STDMETHODIMP_(ULONG) CImpIMalloc::AddRef(void)
  57.     {
  58.     ++m_cRef;
  59.     return m_pUnkOuter->AddRef();
  60.     }
  61.  
  62. STDMETHODIMP_(ULONG) CImpIMalloc::Release(void)
  63.     {
  64.     --m_cRef;
  65.     return m_pUnkOuter->Release();
  66.     }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. /*
  74.  * CImpIMalloc::Alloc
  75.  *
  76.  * Purpose:
  77.  *  Allocates memory according to the rules of the allocator
  78.  *  object with this interface.
  79.  *
  80.  * Parameters:
  81.  *  cb              ULONG number of bytes to allocate.
  82.  *
  83.  * Return Value:
  84.  *  void *          Pointer to the reallocated memory
  85.  */
  86.  
  87.  
  88. STDMETHODIMP_(void *) CImpIMalloc::Alloc(ULONG cb)
  89.     {
  90.     return NULL;
  91.     }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. /*
  98.  * CImpIMalloc::Realloc
  99.  *
  100.  * Purpose:
  101.  *  Reallocates a previous allocation to a different size.
  102.  *
  103.  * Parameters:
  104.  *  pv              void * to the previously allocated memory.
  105.  *  cb              ULONG with the new size.
  106.  *
  107.  * Return Value:
  108.  *  void *          Pointer to the reallocated memory
  109.  */
  110.  
  111. STDMETHODIMP_(void *) CImpIMalloc::Realloc(void *pv, ULONG cb)
  112.     {
  113.     return NULL;
  114.     }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. /*
  121.  * CImpIMalloc::Free
  122.  *
  123.  * Purpose:
  124.  *  Frees and allocation from Alloc.
  125.  *
  126.  * Parameters:
  127.  *  pv              void * of the allocation to free.
  128.  *
  129.  * Return Value:
  130.  *  None
  131.  */
  132.  
  133.  
  134. STDMETHODIMP_(void) CImpIMalloc::Free(void *pv)
  135.     {
  136.     return;
  137.     }
  138.  
  139.  
  140.  
  141.  
  142.  
  143. /*
  144.  * CImpIMalloc::GetSize
  145.  *
  146.  * Purpose:
  147.  *  Return the size of an allocation.
  148.  *
  149.  * Parameters:
  150.  *  pv              void * of the allocation in question.
  151.  *
  152.  * Return Value:
  153.  *  ULONG           The number of bytes in the allocation.
  154.  */
  155.  
  156.  
  157. STDMETHODIMP_(ULONG) CImpIMalloc::GetSize(void *pv)
  158.     {
  159.     return 0;
  160.     }
  161.  
  162.  
  163.  
  164.  
  165.  
  166. /*
  167.  * CImpIMalloc::DidAlloc
  168.  *
  169.  * Purpose:
  170.  *  Answers if this allocator allocated the given block of memory.
  171.  *
  172.  * Parameters:
  173.  *  pv              void * of the allocation in question.
  174.  *
  175.  * Return Value:
  176.  *  int             1 if the allocation was made by this allocator,
  177.  *                  0 if not, -1 if the answer is indeterminate.
  178.  */
  179.  
  180.  
  181. STDMETHODIMP_(int) CImpIMalloc::DidAlloc(void *pv)
  182.     {
  183.     return -1;
  184.     }
  185.  
  186.  
  187.  
  188.  
  189.  
  190. /*
  191.  * CImpIMalloc::HeapMinimize
  192.  *
  193.  * Purpose:
  194.  *  Releases unused memory to the operating system, minimizing the
  195.  *  heap.
  196.  *
  197.  * Parameters:
  198.  *  None
  199.  *
  200.  * Return Value:
  201.  *  None
  202.  */
  203.  
  204.  
  205. STDMETHODIMP_(void) CImpIMalloc::HeapMinimize(void)
  206.     {
  207.     return;
  208.     }
  209.