home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / SCENEOP / SCOP / SCOPFAC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  3.2 KB  |  131 lines

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