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.

132 lines
3.0 KiB

  1. #pragma once
  2. #include "CUnknown.h"
  3. // Forward reference
  4. class CFactoryData ;
  5. class CUnknown ;
  6. // Global data used by CFactory
  7. extern CFactoryData g_FactoryDataArray[] ;
  8. extern int g_cFactoryDataEntries ;
  9. typedef HRESULT (*FPCREATEINSTANCE)(IUnknown*, CUnknown**) ;
  10. ///////////////////////////////////////////////////////////
  11. //
  12. // CFactoryData
  13. // - Information CFactory needs to create a component
  14. class CFactoryData
  15. {
  16. public:
  17. // The class ID for the component
  18. const CLSID* m_pCLSID ;
  19. // Pointer to the function that creates it
  20. FPCREATEINSTANCE CreateInstance;
  21. // Pointer to running class factory for this component
  22. IClassFactory* m_pIClassFactory;
  23. // Magic cookie to identify running object
  24. DWORD m_dwRegister ;
  25. // Helper function for finding the class ID
  26. BOOL IsClassID(const CLSID& clsid) const
  27. { return (*m_pCLSID == clsid) ;}
  28. } ;
  29. ///////////////////////////////////////////////////////////
  30. //
  31. // Class Factory
  32. //
  33. class CFactory : public IClassFactory
  34. {
  35. public:
  36. // IUnknown methods
  37. STDMETHODIMP QueryInterface(REFIID riid,void ** ppv);
  38. STDMETHODIMP_(ULONG) AddRef();
  39. STDMETHODIMP_(ULONG) Release();
  40. // IClassFactory
  41. STDMETHOD(CreateInstance)(IUnknown* pUnknownOuter,
  42. /*in*/ const IID& iid,
  43. /*out*/ void** ppv) ;
  44. STDMETHOD(LockServer)(BOOL bLock) ;
  45. // ctor
  46. CFactory(/* in */ const CFactoryData* pFactoryData) ;
  47. // dtor
  48. ~CFactory();
  49. // Static FactoryData support functions
  50. // --------------Support Common to Inproc/OutProc--------------------------
  51. // Helper function for DllCanUnloadNow
  52. static BOOL IsLocked()
  53. { return (s_cServerLocks > 0) ;}
  54. // Function to determine if component can be unloaded
  55. static HRESULT CanUnloadNow() ;
  56. #ifdef _OUTPROC_SERVER_
  57. // ---------------------OutProc server support-----------------------------
  58. static HRESULT StartFactories() ;
  59. static void StopFactories() ;
  60. static DWORD s_dwThreadID ;
  61. // Shut down the application.
  62. static void CloseExe()
  63. {
  64. if (CanUnloadNow() == S_OK)
  65. {
  66. ::PostThreadMessage(s_dwThreadID, WM_QUIT, 0, 0) ;
  67. }
  68. }
  69. #else
  70. // ---------------------InProc server support-----------------------------
  71. // DllGetClassObject support
  72. static HRESULT GetClassObject(const CLSID& clsid,
  73. /*in*/ const IID& iid,
  74. /*out*/ void** ppv) ;
  75. // CloseExe doesn't do anything if we are in process.
  76. static void CloseExe() { /*Empty*/ }
  77. #endif // _OUTPROC_SERVER
  78. public:
  79. // Reference Count
  80. DWORD m_cRef ;
  81. // Pointer to information about class this factory creates
  82. const CFactoryData* m_pFactoryData ;
  83. // Count of locks
  84. static LONG s_cServerLocks ;
  85. // Module handle
  86. static HMODULE s_hModule ;
  87. } ;