home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP20 / COMPOBJ.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  1.1 KB  |  47 lines

  1. /*----------------------------------------------
  2.    COMPOBJ.CPP -- Component Object registration
  3.                   (c) Paul Yao, 1996
  4.   ----------------------------------------------*/
  5. #include <windows.h>
  6. #include "pubmem.h"
  7.  
  8. int cObject    = 0 ;
  9. int cLockCount = 0 ;
  10.  
  11. //-------------------------------------------------------------------
  12. HRESULT APIENTRY 
  13. DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppvObj)
  14.      {
  15.      // Initialize "out" pointer to known value
  16.      *ppvObj = NULL ;
  17.  
  18.      if (rclsid != CLSID_ALLOCATOR)
  19.           {
  20.           return CLASS_E_CLASSNOTAVAILABLE ;
  21.           }
  22.  
  23.      DClassFactory *pClassFactory = new DClassFactory () ;
  24.      if (pClassFactory == NULL)
  25.           {
  26.           return E_OUTOFMEMORY ;
  27.           }
  28.      else
  29.           {
  30.           return pClassFactory->QueryInterface (riid, ppvObj) ;
  31.           }
  32.      }
  33.  
  34. //-------------------------------------------------------------------
  35. HRESULT APIENTRY 
  36. DllCanUnloadNow (void)
  37.      {
  38.      if (cObject > 0 || cLockCount > 0)
  39.           {
  40.           return S_FALSE ;
  41.           }
  42.      else
  43.           {
  44.           return S_OK ;
  45.           }
  46.      }
  47.