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.

113 lines
3.1 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: CFactory.h
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 26 Dec, 1997
  12. *
  13. * DESCRIPTION:
  14. * Declarations and definitions for Class factory.
  15. *
  16. *******************************************************************************/
  17. typedef HRESULT (*FPCREATEINSTANCE)(const IID& iid, void** ppv);
  18. // FACTORY_DATA - Information CFactory needs to create a component
  19. typedef struct _FACTORY_DATA
  20. {
  21. FPCREATEINSTANCE CreateInstance; // Pointer to creating function.
  22. IClassFactory* pIClassFactory; // Pointer to running class factory.
  23. DWORD dwRegister; // ID for running object.
  24. const CLSID* pclsid; // The class ID for the component.
  25. const GUID* plibid; // Type library ID.
  26. // Registry strings:
  27. LPCTSTR szRegName; // Name of the component.
  28. LPCTSTR szProgID; // Program ID.
  29. LPCTSTR szVerIndProgID; // Version-independent program ID.
  30. LPCTSTR szService; // Name of service.
  31. } FACTORY_DATA, *PFACTORY_DATA;
  32. // Class Factory
  33. class CFactory : public IClassFactory
  34. {
  35. public:
  36. // IUnknown
  37. virtual HRESULT __stdcall QueryInterface(const IID& iid, void** ppv) ;
  38. virtual ULONG __stdcall AddRef() ;
  39. virtual ULONG __stdcall Release() ;
  40. // IClassFactory
  41. virtual HRESULT __stdcall CreateInstance(IUnknown* pUnknownOuter,
  42. const IID& iid,
  43. void** ppv) ;
  44. virtual HRESULT __stdcall LockServer(BOOL bLock) ;
  45. // Constructor - Pass pointer to data of component to create.
  46. CFactory(const PFACTORY_DATA pFactoryData);
  47. // Destructor
  48. ~CFactory() { }
  49. // Static FactoryData support functions
  50. // Helper function for CanUnloadNow
  51. static BOOL IsLocked()
  52. { return (s_cServerLocks > 0) ;}
  53. // Functions to [un]register all components
  54. static HRESULT RegisterUnregisterAll(
  55. PFACTORY_DATA pFactoryData,
  56. UINT uiFactoryDataCount,
  57. BOOLEAN bRegister,
  58. BOOLEAN bOutProc);
  59. // Function to determine if component can be unloaded
  60. static HRESULT CanUnloadNow() ;
  61. // Out-of-process server support
  62. static BOOL StartFactories(
  63. PFACTORY_DATA pFactoryData,
  64. UINT uiFactoryDataCount);
  65. static void StopFactories(
  66. PFACTORY_DATA pFactoryData,
  67. UINT uiFactoryDataCount);
  68. static DWORD s_dwThreadID ;
  69. // Shut down the application.
  70. static void CloseExe()
  71. {
  72. if (CanUnloadNow() == S_OK)
  73. {
  74. ::PostThreadMessage(s_dwThreadID, WM_QUIT, 0, 0) ;
  75. }
  76. }
  77. public:
  78. // Reference Count
  79. LONG m_cRef ;
  80. // Pointer to information about class this factory creates
  81. PFACTORY_DATA m_pFactoryData;
  82. // Count of locks
  83. static LONG s_cServerLocks;
  84. // Module handle
  85. static HMODULE s_hModule;
  86. } ;