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.

170 lines
5.4 KiB

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