Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.3 KiB

  1. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  2. // Factory.h
  3. #pragma once
  4. class CFactoryData;
  5. class CFactory;
  6. // Global data used by CFactory
  7. extern CFactoryData g_FactoryDataArray[] ;
  8. extern int g_cFactoryDataEntries ;
  9. typedef HRESULT (*FPCREATEINSTANCE)(CUnknown**) ;
  10. ///////////////////////////////////////////////////////////
  11. //
  12. // CFactoryData
  13. // - Information CFactory needs to create a component
  14. // supported by the DLL
  15. //
  16. class CFactoryData
  17. {
  18. public:
  19. // The class ID for the component
  20. const CLSID* m_pCLSID ;
  21. // Pointer to the function that creates it
  22. FPCREATEINSTANCE CreateInstance ;
  23. // Name of the component to register in the registry
  24. LPCWSTR m_RegistryName ;
  25. // ProgID
  26. LPCWSTR m_szProgID ;
  27. // Version-independent ProgID
  28. LPCWSTR m_szVerIndProgID ;
  29. // Helper function for finding the class ID
  30. BOOL IsClassID(const CLSID& clsid) const
  31. { return (*m_pCLSID == clsid) ;}
  32. };
  33. class CFactory : public IClassFactory
  34. {
  35. public:
  36. // IUnknown
  37. STDMETHOD(QueryInterface) (const IID& iid, void** ppv);
  38. STDMETHOD_(ULONG,AddRef) ();
  39. STDMETHOD_(ULONG,Release)();
  40. // IClassFactory
  41. STDMETHOD(CreateInstance) (IUnknown* pUnknownOuter,
  42. const IID& iid,
  43. void** ppv);
  44. STDMETHOD(LockServer) (BOOL bLock);
  45. // Constructor - Pass pointer to data of component to create.
  46. CFactory(const CFactoryData* pFactoryData) ;
  47. // Destructor
  48. ~CFactory() { LockServer(FALSE); }
  49. //
  50. // Static FactoryData support functions
  51. //
  52. // DllGetClassObject support
  53. static HRESULT GetClassObject(const CLSID& clsid,
  54. const IID& iid,
  55. void** ppv) ;
  56. // Helper function for DllCanUnloadNow
  57. static BOOL IsLocked()
  58. { return (s_cServerLocks > 0) ;}
  59. // Functions to [un]register all components
  60. static HRESULT RegisterAll() ;
  61. static HRESULT UnregisterAll() ;
  62. // Function to determine if component can be unloaded
  63. static HRESULT CanUnloadNow() ;
  64. public:
  65. // Reference count
  66. long m_cRef ;
  67. // Pointer to information about class this factory creates
  68. const CFactoryData* m_pFactoryData ;
  69. // Count of locks
  70. static LONG s_cServerLocks ;
  71. // Module handle
  72. static HMODULE s_hModule ;
  73. };