1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: OLE automation utilities
4 // Author: Julian Smart
8 // Copyright: (c) 1998, Julian Smart
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma interface "automtn.h"
16 #ifndef _WX_AUTOMTN_H_
17 #define _WX_AUTOMTN_H_
19 #include "wx/object.h"
20 #include "wx/variant.h"
22 typedef void WXIDISPATCH
;
23 typedef unsigned short* WXBSTR
;
27 * Wraps up an IDispatch pointer and invocation; does variant conversion.
30 class WXDLLEXPORT wxAutomationObject
: public wxObject
33 wxAutomationObject(WXIDISPATCH
* dispatchPtr
= NULL
);
34 ~wxAutomationObject();
36 // Set/get dispatch pointer
37 inline void SetDispatchPtr(WXIDISPATCH
* dispatchPtr
) { m_dispatchPtr
= dispatchPtr
; };
38 inline WXIDISPATCH
* GetDispatchPtr() const { return m_dispatchPtr
; }
40 // Get a dispatch pointer from the current object associated
41 // with a class id, such as "Excel.Application"
42 bool GetInstance(const wxString
& classId
) const;
44 // Get a dispatch pointer from a new instance of the the class
45 bool CreateInstance(const wxString
& classId
) const;
47 // Low-level invocation function. Pass either an array of variants,
48 // or an array of pointers to variants.
49 bool Invoke(const wxString
& member
, int action
,
50 wxVariant
& retValue
, int noArgs
, wxVariant args
[], const wxVariant
* ptrArgs
[] = 0) const;
52 // Invoke a member function
53 wxVariant
CallMethod(const wxString
& method
, int noArgs
, wxVariant args
[]);
55 // Convenience function
56 wxVariant
CallMethod(const wxString
& method
,
57 const wxVariant
& arg1
= wxNullVariant
, const wxVariant
& arg2
= wxNullVariant
,
58 const wxVariant
& arg3
= wxNullVariant
, const wxVariant
& arg4
= wxNullVariant
,
59 const wxVariant
& arg5
= wxNullVariant
, const wxVariant
& arg6
= wxNullVariant
);
62 wxVariant
GetProperty(const wxString
& property
, int noArgs
= 0, wxVariant args
[] = (wxVariant
*) NULL
) const;
63 wxVariant
GetProperty(const wxString
& property
,
64 const wxVariant
& arg1
, const wxVariant
& arg2
= wxNullVariant
,
65 const wxVariant
& arg3
= wxNullVariant
, const wxVariant
& arg4
= wxNullVariant
,
66 const wxVariant
& arg5
= wxNullVariant
, const wxVariant
& arg6
= wxNullVariant
);
68 bool PutProperty(const wxString
& property
, int noArgs
, wxVariant args
[]) ;
69 bool PutProperty(const wxString
& property
,
70 const wxVariant
& arg1
, const wxVariant
& arg2
= wxNullVariant
,
71 const wxVariant
& arg3
= wxNullVariant
, const wxVariant
& arg4
= wxNullVariant
,
72 const wxVariant
& arg5
= wxNullVariant
, const wxVariant
& arg6
= wxNullVariant
);
74 // Uses DISPATCH_PROPERTYGET
75 // and returns a dispatch pointer. The calling code should call Release
76 // on the pointer, though this could be implicit by constructing an wxAutomationObject
77 // with it and letting the destructor call Release.
78 WXIDISPATCH
* GetDispatchProperty(const wxString
& property
, int noArgs
, wxVariant args
[]) const;
80 // A way of initialising another wxAutomationObject with a dispatch object,
81 // without having to deal with nasty IDispatch pointers.
82 bool GetObject(wxAutomationObject
& obj
, const wxString
& property
, int noArgs
= 0, wxVariant args
[] = (wxVariant
*) NULL
) const;
85 static bool ConvertVariantToOle(const wxVariant
& variant
, VARIANTARG
& oleVariant
) ;
86 static bool ConvertOleToVariant(const VARIANTARG
& oleVariant
, wxVariant
& variant
) ;
89 WXIDISPATCH
* m_dispatchPtr
;
92 // wrapper around BSTR type (by Vadim Zeitlin)
94 class WXDLLEXPORT BasicString
98 BasicString(const char *sz
);
102 // just get the string
103 operator BSTR() const { return m_wzBuf
; }
104 // retrieve a copy of our string - caller must SysFreeString() it later!
105 BSTR
Get() const { return SysAllocString(m_wzBuf
); }
108 // @@@ not implemented (but should be)
109 BasicString(const BasicString
&);
110 BasicString
& operator=(const BasicString
&);
112 OLECHAR
*m_wzBuf
; // actual string