automtn.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/ole/automtn.h
  3. // Purpose: OLE automation utilities
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 11/6/98
  7. // Copyright: (c) 1998, Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_AUTOMTN_H_
  11. #define _WX_AUTOMTN_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_OLE_AUTOMATION
  14. #include "wx/object.h"
  15. #include "wx/variant.h"
  16. typedef void WXIDISPATCH;
  17. typedef unsigned short* WXBSTR;
  18. typedef unsigned long WXLCID;
  19. #ifdef GetObject
  20. #undef GetObject
  21. #endif
  22. // Flags used with wxAutomationObject::GetInstance()
  23. enum wxAutomationInstanceFlags
  24. {
  25. // Only use the existing instance, never create a new one.
  26. wxAutomationInstance_UseExistingOnly = 0,
  27. // Create a new instance if there are no existing ones.
  28. wxAutomationInstance_CreateIfNeeded = 1,
  29. // Do not log errors if we failed to get the existing instance because none
  30. // is available.
  31. wxAutomationInstance_SilentIfNone = 2
  32. };
  33. /*
  34. * wxAutomationObject
  35. * Wraps up an IDispatch pointer and invocation; does variant conversion.
  36. */
  37. class WXDLLIMPEXP_CORE wxAutomationObject: public wxObject
  38. {
  39. public:
  40. wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL);
  41. virtual ~wxAutomationObject();
  42. // Set/get dispatch pointer
  43. void SetDispatchPtr(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; }
  44. WXIDISPATCH* GetDispatchPtr() const { return m_dispatchPtr; }
  45. bool IsOk() const { return m_dispatchPtr != NULL; }
  46. // Get a dispatch pointer from the current object associated
  47. // with a ProgID, such as "Excel.Application"
  48. bool GetInstance(const wxString& progId,
  49. int flags = wxAutomationInstance_CreateIfNeeded) const;
  50. // Get a dispatch pointer from a new instance of the class
  51. bool CreateInstance(const wxString& progId) const;
  52. // Low-level invocation function. Pass either an array of variants,
  53. // or an array of pointers to variants.
  54. bool Invoke(const wxString& member, int action,
  55. wxVariant& retValue, int noArgs, wxVariant args[], const wxVariant* ptrArgs[] = 0) const;
  56. // Invoke a member function
  57. wxVariant CallMethod(const wxString& method, int noArgs, wxVariant args[]);
  58. wxVariant CallMethodArray(const wxString& method, int noArgs, const wxVariant **args);
  59. // Convenience function
  60. wxVariant CallMethod(const wxString& method,
  61. const wxVariant& arg1 = wxNullVariant, const wxVariant& arg2 = wxNullVariant,
  62. const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant,
  63. const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant);
  64. // Get/Put property
  65. wxVariant GetProperty(const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const;
  66. wxVariant GetPropertyArray(const wxString& property, int noArgs, const wxVariant **args) const;
  67. wxVariant GetProperty(const wxString& property,
  68. const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant,
  69. const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant,
  70. const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant);
  71. bool PutPropertyArray(const wxString& property, int noArgs, const wxVariant **args);
  72. bool PutProperty(const wxString& property, int noArgs, wxVariant args[]) ;
  73. bool PutProperty(const wxString& property,
  74. const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant,
  75. const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant,
  76. const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant);
  77. // Uses DISPATCH_PROPERTYGET
  78. // and returns a dispatch pointer. The calling code should call Release
  79. // on the pointer, though this could be implicit by constructing an wxAutomationObject
  80. // with it and letting the destructor call Release.
  81. WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, wxVariant args[]) const;
  82. WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, const wxVariant **args) const;
  83. // A way of initialising another wxAutomationObject with a dispatch object,
  84. // without having to deal with nasty IDispatch pointers.
  85. bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const;
  86. bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs, const wxVariant **args) const;
  87. // Returns the locale identifier used in automation calls. The default is
  88. // LOCALE_SYSTEM_DEFAULT. Objects obtained by GetObject() inherit the
  89. // locale identifier from the one that created them.
  90. WXLCID GetLCID() const;
  91. // Sets the locale identifier to be used in automation calls performed by
  92. // this object. The default is LOCALE_SYSTEM_DEFAULT.
  93. void SetLCID(WXLCID lcid);
  94. // Returns the flags used for conversions between wxVariant and OLE
  95. // VARIANT, see wxOleConvertVariantFlags. The default value is
  96. // wxOleConvertVariant_Default but all the objects obtained by GetObject()
  97. // inherit the flags from the one that created them.
  98. long GetConvertVariantFlags() const;
  99. // Sets the flags used for conversions between wxVariant and OLE VARIANT,
  100. // see wxOleConvertVariantFlags (default is wxOleConvertVariant_Default.
  101. void SetConvertVariantFlags(long flags);
  102. public: // public for compatibility only, don't use m_dispatchPtr directly.
  103. WXIDISPATCH* m_dispatchPtr;
  104. private:
  105. WXLCID m_lcid;
  106. long m_convertVariantFlags;
  107. wxDECLARE_NO_COPY_CLASS(wxAutomationObject);
  108. };
  109. #endif // wxUSE_OLE_AUTOMATION
  110. #endif // _WX_AUTOMTN_H_