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

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