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

  1. /* $Id: ScopDll.cpp 1.2 1996/07/23 21:41:40 Damien Exp $ */ 
  2.  
  3. ////////////////////////////////////////////////////////////////////////
  4. //   Scene Operation Example : stairs                                    //
  5. //--------------------------------------------------------------------//
  6. //   DLL Management                                                   //
  7. ////////////////////////////////////////////////////////////////////////   
  8.  
  9. #ifndef __SCOPDLL__
  10. #include "ScOpdll.h"
  11. #endif
  12.  
  13. #ifndef __COMSCOP__
  14. #include "COMScOp.h"
  15. #endif
  16.  
  17. #ifndef __SCOPFAC__
  18. #include "ScOpFac.h"
  19. #endif
  20.  
  21. #ifndef __3DCOFAIL__
  22. #include "3DCoFail.h"
  23. #endif
  24.  
  25. STDAPI DllInitRDCom(IShUtilities* shellUtilities) {
  26.     InitCoFailure(shellUtilities);
  27.     return S_OK;
  28.     }
  29.  
  30. //------------------------------------------------------------------------
  31. /*
  32.  * DllGetClassObject
  33.  *
  34.  * This function gives a IClassFactory with the appropriate CLSID.
  35.  * This DLL must be in the registration database as a InProcServer
  36.  * for the correct CLSID
  37.  *
  38.  * Parameters:
  39.  *  clsID           REFCLSID that identifies the class factory
  40.  *                  desired.  Since this parameter is passed this
  41.  *                  DLL can handle any number of objects simply
  42.  *                  by returning different class factories here
  43.  *                  for different CLSIDs.
  44.  *
  45.  *  riid            REFIID specifying the interface the caller wants
  46.  *                  on the class object, usually IID_ClassFactory.
  47.  *
  48.  *  ppv             LPVOID FAR* in which to return the interface
  49.  *                  pointer.
  50.  *
  51.  * Returns NOERROR on success, otherwise an error code
  52.  */
  53.  
  54. STDAPI DllGetClassObject(REFCLSID rclsid
  55.     , REFIID riid, LPVOID FAR* ppv) {
  56.   if (!IsEqualCLSID(rclsid, CLSID_SceneOp))
  57.       return ResultFromScode(E_FAIL);
  58.  
  59.   //Check that we can provide the interface
  60.   if (!IsEqualIID(riid, IID_IUnknown) && !IsEqualIID(riid, IID_IClassFactory))
  61.       return ResultFromScode(E_NOINTERFACE);
  62.  
  63.   //Return our IClassFactory for the correct objects
  64.   if (IsEqualCLSID(rclsid,CLSID_SceneOp))
  65.     *ppv=(LPVOID) new SceneOpClassFactory();
  66.  
  67.   if (*ppv == NULL)
  68.       return ResultFromScode(E_OUTOFMEMORY);
  69.  
  70.   //AddRef the object through any interface we return
  71.   ((LPUNKNOWN)*ppv)->AddRef();
  72.  
  73.   return NOERROR;
  74.   }
  75.  
  76.  
  77. /*
  78.  * DllCanUnloadNow
  79.  *
  80.  *  Answers if the DLL can be unload from the memory
  81.  *
  82.  *  This function doesn't need any parameter
  83.  *
  84.  *  Returns TRUE if nothing is using us, FALSE otherwise.
  85.  */
  86.  
  87. STDAPI DllCanUnloadNow() {
  88.   SCODE   sc;
  89.  
  90.   //Our answer is whether there are any object or locks
  91.   sc=(0L==global_count_Obj && 0L==global_count_Lock) ? S_OK : S_FALSE;
  92.   return ResultFromScode(sc);
  93.   }
  94.  
  95. //------------------------------------------------------------------------
  96. //Count number of objects and number of locks.
  97. long       global_count_Obj  = 0;
  98. long       global_count_Lock = 0;
  99.  
  100.