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.

131 lines
5.1 KiB

  1. // Copyright 1995-1997 Microsoft Corporation. All Rights Reserved.
  2. #if _MSC_VER > 1000
  3. #pragma once
  4. #endif
  5. #ifndef _AUTOOBJ_H_
  6. #define _AUTOOBJ_H_
  7. #include "Unknown.H"
  8. //=--------------------------------------------------------------------------=
  9. // the constants in this header file uniquely identify your automation objects.
  10. // make sure that for each object you have in the g_ObjectInfo table, you have
  11. // a constant in this header file.
  12. //
  13. #include "LocalSrv.H"
  14. //=--------------------------------------------------------------------------=
  15. // AUTOMATIONOBJECTINFO
  16. //=--------------------------------------------------------------------------=
  17. // for each automation object type you wish to expose to the programmer/user
  18. // that is not a control, you must fill out one of these structures. if the
  19. // object isn't CoCreatable, then the first four fields should be empty.
  20. // otherwise, they should be filled in with the appropriate information.
  21. // use the macro DEFINE_AUTOMATIONOBJECT to both declare and define your object.
  22. // make sure you have an entry in the global table of objects, g_ObjectInfo
  23. // in the main .Cpp file for your InProc server.
  24. #ifndef NDEF_AUTOMATIONOBJECTINFO
  25. typedef struct {
  26. UNKNOWNOBJECTINFO unknowninfo; // fill in with 0's if we're not CoCreatable
  27. long lVersion; // Version number of Object. ONLY USE IF YOU'RE CoCreatable!
  28. const IID *riid; // object's type
  29. LPCSTR pszHelpFile; // the helpfile for this automation object.
  30. ITypeInfo *pTypeInfo; // typeinfo for this object
  31. UINT cTypeInfo; // number of refs to the type info
  32. } AUTOMATIONOBJECTINFO;
  33. #endif
  34. // macros to manipulate the AUTOMATIONOBJECTINFO in the global table table.
  35. #define VERSIONOFOBJECT(index) ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->lVersion
  36. #define INTERFACEOFOBJECT(index) *(((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->riid)
  37. #define PPTYPEINFOOFOBJECT(index) &((((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pTypeInfo))
  38. #define PTYPEINFOOFOBJECT(index) ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pTypeInfo
  39. #define CTYPEINFOOFOBJECT(index) ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->cTypeInfo
  40. #define HELPFILEOFOBJECT(index) ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pszHelpFile
  41. #ifndef INITOBJECTS
  42. #define DEFINE_AUTOMATIONOBJECT(name, clsid, objname, fn, ver, riid, pszh) \
  43. extern AUTOMATIONOBJECTINFO name##Object \
  44. #else
  45. #define DEFINE_AUTOMATIONOBJECT(name, clsid, objname, fn, ver, riid, pszh) \
  46. AUTOMATIONOBJECTINFO name##Object = { { clsid, objname, fn }, ver, riid, pszh, NULL, 0} \
  47. #endif // INITOBJECTS
  48. //=--------------------------------------------------------------------------=
  49. // Standard Dispatch and SupportErrorInfo
  50. //=--------------------------------------------------------------------------=
  51. // all objects should declare these in their class definitions so that they
  52. // get standard implementations of IDispatch and ISupportErrorInfo.
  53. //
  54. #define DECLARE_STANDARD_DISPATCH() \
  55. STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { \
  56. return CAutomationObject::GetTypeInfoCount(pctinfo); \
  57. } \
  58. STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo **ppTypeInfoOut) { \
  59. return CAutomationObject::GetTypeInfo(itinfo, lcid, ppTypeInfoOut); \
  60. } \
  61. STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR **rgszNames, UINT cnames, LCID lcid, DISPID *rgdispid) { \
  62. return CAutomationObject::GetIDsOfNames(riid, rgszNames, cnames, lcid, rgdispid); \
  63. } \
  64. STDMETHOD(Invoke)(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pVarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr) { \
  65. return CAutomationObject::Invoke(dispid, riid, lcid, wFlags, pdispparams, pVarResult, pexcepinfo, puArgErr); \
  66. } \
  67. #define DECLARE_STANDARD_SUPPORTERRORINFO() \
  68. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid) { \
  69. return CAutomationObject::InterfaceSupportsErrorInfo(riid); \
  70. } \
  71. //=--------------------------------------------------------------------------=
  72. // CAutomationObject
  73. //=--------------------------------------------------------------------------=
  74. // global class that all automation objects can inherit from to give them a
  75. // bunch of implementation for free, namely IDispatch and ISupportsErrorInfo
  76. class CAutomationObject : public CUnknownObject {
  77. public:
  78. // aggreation query interface support
  79. virtual HRESULT InternalQueryInterface(REFIID riid, void **ppvObjOut);
  80. // IDispatch methods
  81. STDMETHOD(GetTypeInfoCount)(UINT *);
  82. STDMETHOD(GetTypeInfo)(UINT, LCID, ITypeInfo **);
  83. STDMETHOD(GetIDsOfNames)(REFIID, OLECHAR **, UINT, LCID, DISPID *);
  84. STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  85. // ISupportErrorInfo methods
  86. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID);
  87. CAutomationObject(IUnknown *, int , void *);
  88. virtual ~CAutomationObject();
  89. // callable functions -- things that most people will find useful.
  90. HRESULT Exception(HRESULT hr, WORD idException, DWORD dwHelpContextID);
  91. protected:
  92. // member variables that derived objects might need to get at information in the
  93. // global object table
  94. int m_ObjectType;
  95. private:
  96. BOOL m_fLoadedTypeInfo;
  97. };
  98. #endif // _AUTOOBJ_H_