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.

129 lines
4.3 KiB

  1. #ifndef _STATIC_CLASS_FACTORY_
  2. #define _STATIC_CLASS_FACTORY_
  3. /*
  4. * Class Factory Implementation for C++ without CTRStartup required.
  5. */
  6. #ifdef __cplusplus
  7. #ifdef UNIX
  8. #define STDMETHODX STDMETHOD
  9. #define STDMETHODX_ STDMETHOD_
  10. #define DECLARE_CLASS_FACTORY(cf) \
  11. class cf: public IClassFactory \
  12. { \
  13. public: \
  14. STDMETHODX (QueryInterface)(REFIID, void **); \
  15. STDMETHODX_(ULONG, AddRef)(); \
  16. STDMETHODX_(ULONG, Release)(); \
  17. \
  18. STDMETHODX (CreateInstance)(IUnknown *, REFIID, void **); \
  19. STDMETHODX (LockServer)(BOOL); \
  20. } \
  21. #else // UNIX
  22. #define STDMETHODX(fn) HRESULT __stdcall fn
  23. #define STDMETHODX_(ret,fn) ret __stdcall fn
  24. #define DECLARE_CLASS_FACTORY(cf) \
  25. class cf \
  26. { \
  27. public: \
  28. void *vtable; \
  29. STDMETHODX (QueryInterface)(REFIID, void **); \
  30. STDMETHODX_(ULONG, AddRef)(); \
  31. STDMETHODX_(ULONG, Release)(); \
  32. \
  33. STDMETHODX (CreateInstance)(IUnknown *, REFIID, void **); \
  34. STDMETHODX (LockServer)(BOOL); \
  35. } \
  36. #endif // UNIX
  37. DECLARE_CLASS_FACTORY( CClassFactory );
  38. struct IClassFactoryVtbl
  39. {
  40. // *** IUnknown methods ***
  41. HRESULT (STDMETHODCALLTYPE CClassFactory::* QueryInterface) (
  42. REFIID riid,
  43. LPVOID FAR* ppvObj) ;
  44. ULONG (STDMETHODCALLTYPE CClassFactory::*AddRef) () ;
  45. ULONG (STDMETHODCALLTYPE CClassFactory::*Release) () ;
  46. // *** IClassFactory methods ***
  47. HRESULT (STDMETHODCALLTYPE CClassFactory::*CreateInstance) (
  48. LPUNKNOWN pUnkOuter,
  49. REFIID riid,
  50. LPVOID FAR* ppvObject) ;
  51. HRESULT (STDMETHODCALLTYPE CClassFactory::*LockServer)(BOOL);
  52. };
  53. typedef struct IClassFactoryVtbl IClassFactoryVtbl;
  54. //
  55. // class CObjectInfo
  56. //
  57. typedef HRESULT (*LPFNCREATEINSTANCE)(IUnknown *punkOuter, REFIID riid, void **ppvOut);
  58. class CObjectInfo : public CClassFactory
  59. {
  60. public:
  61. CObjectInfo(CLSID const* pclsidin, LPFNCREATEINSTANCE pfnCreatein)
  62. { pclsid = pclsidin; pfnCreate = pfnCreatein; }
  63. CLSID const* pclsid;
  64. LPFNCREATEINSTANCE pfnCreate;
  65. };
  66. const IClassFactoryVtbl c_CFVtbl = {
  67. CClassFactory::QueryInterface,
  68. CClassFactory::AddRef,
  69. CClassFactory::Release,
  70. CClassFactory::CreateInstance,
  71. CClassFactory::LockServer
  72. };
  73. //
  74. // CLASS FACTORY TABLE STUFF
  75. //
  76. typedef struct {
  77. const IClassFactoryVtbl *cf;
  78. const CLSID *rclsid;
  79. HRESULT (*pfnCreate)(IUnknown *, REFIID, void **);
  80. } OBJ_ENTRY;
  81. #ifdef UNIX
  82. #define CF_TABLE_BEGIN(cfTable) const CObjectInfo cfTable[] = {
  83. #define CF_TABLE_ENTRY(pclsid, pfnCreate) CObjectInfo( pclsid, pfnCreate),
  84. #define CF_TABLE_END(cfTable) \
  85. CF_TABLE_ENTRY(NULL, NULL) };
  86. #define GET_ICLASSFACTORY(ptr) SAFECAST( ptr, IClassFactory *)
  87. #else
  88. #define CF_TABLE_BEGIN(cfTable) const OBJ_ENTRY cfTable##_tble[] = {
  89. #define CF_TABLE_ENTRY(pClsid, pfnCreate ) { &c_CFVtbl, pClsid, pfnCreate },
  90. #define CF_TABLE_END(cfTable) \
  91. CF_TABLE_ENTRY(NULL, NULL) }; \
  92. const CObjectInfo *cfTable = (CObjectInfo *)cfTable##_tble;
  93. #define GET_ICLASSFACTORY(ptr) (&(ptr->vtable))
  94. #endif
  95. #endif // __cplusplus
  96. #endif // _STATIC_CLASS_FACTORY_