Source code of Windows XP (NT5)
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.

154 lines
5.2 KiB

  1. #ifndef _STATIC_CLASS_FACTORY_
  2. #define _STATIC_CLASS_FACTORY_
  3. #define VERSION_2 2 // so we don't get confused by too many integers
  4. #define VERSION_1 1
  5. #define VERSION_0 0
  6. #define COCREATEONLY NULL,NULL,VERSION_0,0,0 // piid,piidEvents,lVersion,dwOleMiscFlags,dwClassFactFlags
  7. #define COCREATEONLY_NOFLAGS NULL,NULL,VERSION_0,0 // piid,piidEvents,lVersion,dwOleMiscFlags
  8. /*
  9. * Class Factory Implementation for C++ without CTRStartup required.
  10. */
  11. #ifdef __cplusplus
  12. #ifdef UNIX
  13. #define STDMETHODX STDMETHOD
  14. #define STDMETHODX_ STDMETHOD_
  15. #define DECLARE_CLASS_FACTORY(cf) \
  16. class cf: public IClassFactory \
  17. { \
  18. public: \
  19. STDMETHODX (QueryInterface)(REFIID, void **); \
  20. STDMETHODX_(ULONG, AddRef)(); \
  21. STDMETHODX_(ULONG, Release)(); \
  22. \
  23. STDMETHODX (CreateInstance)(IUnknown *, REFIID, void **); \
  24. STDMETHODX (LockServer)(BOOL); \
  25. } \
  26. #else // UNIX
  27. #define STDMETHODX(fn) HRESULT STDMETHODCALLTYPE fn
  28. #define STDMETHODX_(ret,fn) ret STDMETHODCALLTYPE fn
  29. #define DECLARE_CLASS_FACTORY(cf) \
  30. class cf \
  31. { \
  32. public: \
  33. IClassFactory *vtable; \
  34. STDMETHODX (QueryInterface)(REFIID, void **); \
  35. STDMETHODX_(ULONG, AddRef)(); \
  36. STDMETHODX_(ULONG, Release)(); \
  37. \
  38. STDMETHODX (CreateInstance)(IUnknown *, REFIID, void **); \
  39. STDMETHODX (LockServer)(BOOL); \
  40. } \
  41. #endif // UNIX
  42. DECLARE_CLASS_FACTORY( CClassFactory );
  43. struct IClassFactoryVtbl
  44. {
  45. // IUnknown
  46. HRESULT (STDMETHODCALLTYPE CClassFactory::*QueryInterface)(REFIID riid, void ** ppvObj);
  47. ULONG (STDMETHODCALLTYPE CClassFactory::*AddRef)();
  48. ULONG (STDMETHODCALLTYPE CClassFactory::*Release)();
  49. // IClassFactory
  50. HRESULT (STDMETHODCALLTYPE CClassFactory::*CreateInstance)(IUnknown *pUnkOuter, REFIID riid, void ** ppvObject);
  51. HRESULT (STDMETHODCALLTYPE CClassFactory::*LockServer)(BOOL);
  52. };
  53. typedef struct IClassFactoryVtbl IClassFactoryVtbl;
  54. //
  55. // class CObjectInfo
  56. //
  57. class CObjectInfo;
  58. typedef CObjectInfo* LPOBJECTINFO;
  59. typedef CObjectInfo const* LPCOBJECTINFO;
  60. typedef HRESULT (*LPFNCREATEOBJINSTANCE)(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi);
  61. class CObjectInfo : public CClassFactory
  62. {
  63. public:
  64. CLSID const* pclsid;
  65. LPFNCREATEOBJINSTANCE pfnCreateInstance;
  66. // for OCs and automation objects:
  67. IID const* piid;
  68. IID const* piidEvents;
  69. long lVersion;
  70. DWORD dwOleMiscFlags;
  71. DWORD dwClassFactFlags;
  72. CObjectInfo(CLSID const* pclsidin, LPFNCREATEOBJINSTANCE pfnCreatein, IID const* piidIn, IID const* piidEventsIn, long lVersionIn, DWORD dwOleMiscFlagsIn, DWORD dwClassFactFlagsIn);
  73. };
  74. #ifndef NO_CFVTBL
  75. const IClassFactoryVtbl c_CFVtbl = {
  76. CClassFactory::QueryInterface,
  77. CClassFactory::AddRef,
  78. CClassFactory::Release,
  79. CClassFactory::CreateInstance,
  80. CClassFactory::LockServer
  81. };
  82. #endif
  83. //
  84. // CLASS FACTORY TABLE STUFF
  85. //
  86. typedef struct tagOBJECTINFO
  87. {
  88. void *cf;
  89. CLSID const* pclsid;
  90. LPFNCREATEOBJINSTANCE pfnCreateInstance;
  91. // for OCs and automation objects:
  92. IID const* piid;
  93. IID const* piidEvents;
  94. long lVersion;
  95. DWORD dwOleMiscFlags;
  96. DWORD dwClassFactFlags;
  97. } OBJECTINFO;
  98. #ifdef UNIX
  99. #define CF_TABLE_BEGIN(cfTable) const CObjectInfo cfTable[] = {
  100. #define CF_TABLE_ENTRY CObjectInfo
  101. #define CF_TABLE_ENTRY_NOFLAGS CObjectInfo
  102. #define CF_TABLE_ENTRY_ALL CObjectInfo
  103. #define CF_TABLE_END(cfTable) \
  104. CF_TABLE_ENTRY(NULL, NULL, COCREATEONLY) };
  105. #define GET_ICLASSFACTORY(ptr) ((IClassFactory *)ptr)
  106. #else // UNIX
  107. #define CF_TABLE_BEGIN(cfTable) const OBJECTINFO cfTable##_tble[] = {
  108. #define CF_TABLE_ENTRY(p1, p2, p3) { (void *)&c_CFVtbl, p1, p2, p3 }
  109. #define CF_TABLE_ENTRY_NOFLAGS(p1, p2, p3, p4) { (void *)&c_CFVtbl, p1, p2, p3, p4 }
  110. #define CF_TABLE_ENTRY_ALL(p1, p2, p3, p4, p5, p6, p7) { (void *)&c_CFVtbl, p1, p2, p3, p4 , p5, p6, p7}
  111. #define CF_TABLE_END(cfTable) \
  112. CF_TABLE_ENTRY(NULL, NULL, COCREATEONLY) }; \
  113. const CObjectInfo *cfTable = (const CObjectInfo *)cfTable##_tble;
  114. #define GET_ICLASSFACTORY(ptr) ((IClassFactory *)&ptr->vtable)
  115. #endif // UNIX
  116. #define DECLARE_CF_TABLE(cfTable) extern const CObjectInfo *cfTable;
  117. #endif // __cplusplus
  118. #endif // _STATIC_CLASS_FACTORY_