home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Macintosh / Samples / gel / GEL / GELFac.cpp < prev    next >
Encoding:
Text File  |  1997-07-09  |  3.4 KB  |  137 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: GELFac.cpp 1.1 1996/07/18 23:59:32 Damien Exp $ */
  3.  
  4. ////////////////////////////////////////////////////////////////////////
  5. //   First Gel Example : Gel Light                                    //
  6. //--------------------------------------------------------------------//
  7. //   Implementation of the Gel Class Factory                          //
  8. //////////////////////////////////////////////////////////////////////// 
  9.  
  10. #ifndef __GELFAC__
  11. #include "GelFac.h"
  12. #endif
  13.  
  14. #ifndef __COMGEL__
  15. #include "COMGEL.h"
  16. #endif
  17.  
  18. #ifndef __GELDLL__
  19. #include "GelDLL.h"
  20. #endif
  21.  
  22. // ***** ClassFactory *****
  23.   
  24. GelLightClassFactory::GelLightClassFactory() {
  25.   m_cRef=0L;  // just created so no reference used
  26.   return;
  27.   }
  28.  
  29.  
  30. GelLightClassFactory::~GelLightClassFactory() {
  31.   return;
  32.   }
  33.  
  34. // IUnknown methods of GelLightClassFactory                                                
  35. STDMETHODIMP GelLightClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv) {
  36.   *ppv=NULL;
  37.  
  38.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  39.     *ppv=(LPVOID)this;
  40.  
  41.   if (*ppv!=NULL) {
  42.     ((LPUNKNOWN)*ppv)->AddRef(); // Add reference if we give a pointer
  43.     return NOERROR;
  44.     }
  45.   else {
  46.     return ResultFromScode(E_NOINTERFACE);
  47.     }
  48.   }
  49.  
  50.  
  51. STDMETHODIMP_(ULONG) GelLightClassFactory::AddRef() {
  52.   return ++m_cRef;
  53.   }
  54.  
  55.  
  56. STDMETHODIMP_(ULONG) GelLightClassFactory::Release() {
  57.   ULONG   UnreleaseRef;
  58.  
  59.   UnreleaseRef=--m_cRef;
  60.  
  61.   if (m_cRef == 0)
  62.     delete this; // No reference left, so delete the GelLightClassFactory
  63.  
  64.   return UnreleaseRef;
  65.   }
  66.  
  67. /*
  68.  * GelLightClassFactory::CreateInstance
  69.  *
  70.  * Parameters:
  71.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  72.  *                  being used in an aggregation.
  73.  *  riid            REFIID identifying the interface the caller
  74.  *                  desires to have for the new object.
  75.  *  ppvObj          LPVOID FAR* in which to store the desired
  76.  *                  interface pointer for the new object.
  77.  *
  78.  * Return Value:
  79.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  80.  *                  if we cannot support the requested interface.
  81.  */
  82.  
  83. STDMETHODIMP GelLightClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
  84.   GelLight*      pObj = NULL;
  85.   HRESULT       hr;
  86.  
  87.   *ppvObj = NULL;
  88.   hr = ResultFromScode(E_OUTOFMEMORY);
  89.  
  90.   //Verify that a controlling unknown asks for IUnknown
  91.   if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
  92.     return ResultFromScode(E_NOINTERFACE);
  93.  
  94.   //Create the object passing function to notify on destruction.
  95.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExLightsourceGel))
  96.     pObj = new GelLight;
  97.   else
  98.     return ResultFromScode(E_NOINTERFACE);
  99.  
  100.   hr=pObj->QueryInterface(IID_I3DExLightsourceGel, ppvObj);
  101.  
  102.   //Kill the object if initial creation failed.
  103.   if (FAILED(hr))
  104.     delete pObj;
  105.   else
  106.     global_count_Obj++;
  107.  
  108.   return hr;
  109.   }
  110.  
  111.  
  112. /*
  113.  * GelLightClassFactory::LockServer
  114.  *
  115.  * Purpose:
  116.  *  Increments or decrements the lock count of the DLL.  If the
  117.  *  lock count goes to zero and there are no objects, the DLL
  118.  *  is allowed to unload.
  119.  *
  120.  * Parameters:
  121.  *  fLock           BOOL specifying whether to increment or
  122.  *                  decrement the lock count.
  123.  *
  124.  * Return Value:
  125.  *  HRESULT         NOERROR always.
  126.  */
  127.  
  128. STDMETHODIMP GelLightClassFactory::LockServer(BOOL fLock) {
  129.   if (fLock)
  130.       global_count_Lock++;
  131.   else
  132.       global_count_Lock--;
  133.  
  134.   return NOERROR;
  135.   }
  136.  
  137.