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