1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/automtn.h
3 // Purpose: interface of wxAutomationObject
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 Automation object creation flags.
12 These flags can be used with wxAutomationObject::GetInstance().
16 enum wxAutomationInstanceFlags
19 Only use the existing instance, never create a new one.
21 This flag can be used to forbid the creation of a new instance if none
24 wxAutomationInstance_UseExistingOnly
= 0,
27 Create a new instance if there are no existing ones.
29 This flag corresponds to the default behaviour of
30 wxAutomationObject::GetInstance() and means that if getting an existing
31 instance failed, we should call wxAutomationObject::CreateInstance() to
34 wxAutomationInstance_CreateIfNeeded
= 1,
37 Do not show an error message if no existing instance is currently
40 All other errors will still be reported as usual.
42 wxAutomationInstance_SilentIfNone
= 2
46 @class wxVariantDataCurrency
48 This class represents a thin wrapper for Microsoft Windows CURRENCY type.
50 It is used for converting between wxVariant and OLE VARIANT
51 with type set to VT_CURRENCY. When wxVariant stores
52 wxVariantDataCurrency, it returns "currency" as its type.
54 An example of setting and getting CURRENCY value to and from wxVariant:
59 // set wxVariant to currency type
60 if ( SUCCEEDED(VarCyFromR8(123.45, &cy)) ) // set cy to 123.45
62 variant.SetData(new wxVariantDataCurrency(cy));
64 // or instead of the line above you could write:
65 // wxVariantDataCurrency wxCy;
67 // variant.SetData(wxCy.Clone());
70 // get CURRENCY value from wxVariant
71 if ( variant.GetType() == "currency" )
73 wxVariantDataCurrency*
74 wxCy = wxDynamicCastVariantData(variant.GetData(), wxVariantDataCurrency);
75 cy = wxCy->GetValue();
85 @see wxAutomationObject, wxVariant, wxVariantData, wxVariantDataErrorCode
87 @header{wx/msw/ole/oleutils.h}
89 class wxVariantDataCurrency
: public wxVariantData
93 Default constructor initializes the object to 0.0.
95 wxVariantDataCurrency();
98 Constructor from CURRENCY.
100 wxVariantDataCurrency(CURRENCY value
);
103 Returns the stored CURRENCY value.
105 CURRENCY
GetValue() const;
108 Sets the stored value to @a value.
110 void SetValue(CURRENCY value
);
113 Returns true if @a data is of wxVariantDataCurency type
114 and contains the same CURRENCY value.
116 virtual bool Eq(wxVariantData
& data
) const;
119 Fills the provided string with the textual representation of this
122 The implementation of this method using @c VarBstrFromCy() Windows API
123 function with LOCALE_USER_DEFAULT.
125 virtual bool Write(wxString
& str
) const;
128 Returns a copy of itself.
130 wxVariantData
* Clone() const;
135 virtual wxString
GetType() const;
138 Converts the value of this object to wxAny.
140 virtual bool GetAsAny(wxAny
* any
) const;
145 @class wxVariantDataErrorCode
147 This class represents a thin wrapper for Microsoft Windows SCODE type
148 (which is the same as HRESULT).
150 It is used for converting between a wxVariant and OLE VARIANT with type set
151 to VT_ERROR. When wxVariant stores wxVariantDataErrorCode, it returns
152 "errorcode" as its type. This class can be used for returning error codes
153 of automation calls or exchanging values with other applications: e.g.
154 Microsoft Excel returns VARIANTs with VT_ERROR type for cell values with
155 errors (one of XlCVError constants, displayed as e.g. "#DIV/0!" or "#REF!"
156 there) etc. See wxVariantDataCurrency for an example of how to exchange
157 values between wxVariant and a native type not directly supported by it.
165 @see wxAutomationObject, wxVariant, wxVariantData, wxVariantDataCurrency
167 @header{wx/msw/ole/oleutils.h}
169 class wxVariantDataErrorCode
: public wxVariantData
173 Constructor initializes the object to @a value or S_OK if no value was
176 wxVariantDataErrorCode(SCODE value
= S_OK
);
179 Returns the stored SCODE value.
181 SCODE
GetValue() const;
184 Set the stored value to @a value.
186 void SetValue(SCODE value
);
189 Returns true if @a data is of wxVariantDataErrorCode type
190 and contains the same SCODE value.
192 virtual bool Eq(wxVariantData
& data
) const;
195 Fills the provided string with the textual representation of this
198 The error code is just a number, so it's output as such.
200 virtual bool Write(wxString
& str
) const;
203 Returns a copy of itself.
205 wxVariantData
* Clone() const;
210 virtual wxString
GetType() const { return wxS("errorcode"); }
213 Converts the value of this object to wxAny.
215 virtual bool GetAsAny(wxAny
* any
) const;
220 @class wxAutomationObject
222 The @b wxAutomationObject class represents an OLE automation object containing
223 a single data member,
224 an IDispatch pointer. It contains a number of functions that make it easy to
226 automation operations, and set and get properties. The class makes heavy use of
229 The usage of these classes is quite close to OLE automation usage in Visual
231 high-level, and the application can specify multiple properties in a single
232 string. The following example
233 gets the current Excel instance, and if it exists, makes the active cell bold.
236 wxAutomationObject excelObject;
237 if (excelObject.GetInstance("Excel.Application"))
238 excelObject.PutProperty("ActiveCell.Font.Bold", @true);
241 Note that this class obviously works under Windows only.
248 @see wxVariant, wxVariantDataCurrency, wxVariantDataErrorCode
250 class wxAutomationObject
: public wxObject
254 Constructor, taking an optional IDispatch pointer which will be released when
258 wxAutomationObject(WXIDISPATCH
* dispatchPtr
= NULL
);
261 Destructor. If the internal IDispatch pointer is non-null, it will be released.
263 ~wxAutomationObject();
267 Calls an automation method for this object. The first form takes a method name,
269 arguments, and an array of variants. The second form takes a method name and
271 constant references to variants. Since the variant class has constructors for
273 data types, and C++ provides temporary objects automatically, both of the
275 are syntactically valid:
277 Note that @a method can contain dot-separated property names, to save the
279 needing to call GetProperty several times using several temporary objects. For
282 wxVariant
CallMethod(const wxString
& method
, int noArgs
,
283 wxVariant args
[]) const;
284 const wxVariant
CallMethod(const wxString
& method
, ... ) const;
288 Creates a new object based on the ProgID, returning @true if the object was
289 successfully created,
292 bool CreateInstance(const wxString
& progId
) const;
295 Checks if the object is in a valid state.
297 Returns @true if the object was successfully initialized or @false if
298 it has no valid IDispatch pointer.
300 @see GetDispatchPtr()
305 Gets the IDispatch pointer.
307 Notice that the return value of this function is an untyped pointer but
308 it can be safely cast to @c IDispatch.
310 void* GetDispatchPtr() const;
313 Retrieves the current object associated with the specified ProgID, and
314 attaches the IDispatch pointer to this object.
316 If attaching to an existing object failed and @a flags includes
317 wxAutomationInstance_CreateIfNeeded flag, a new object will be created.
318 Otherwise this function will normally log an error message which may be
319 undesirable if the object may or may not exist. The
320 wxAutomationInstance_SilentIfNone flag can be used to prevent the error
321 from being logged in this case.
323 Returns @true if a pointer was successfully retrieved, @false
326 Note that this cannot cope with two instances of a given OLE object being
327 active simultaneously,
328 such as two copies of Excel running. Which object is referenced cannot
329 currently be specified.
331 @param progId COM ProgID, e.g. "Excel.Application"
332 @param flags The creation flags (this parameters was added in wxWidgets
335 bool GetInstance(const wxString
& progId
,
336 int flags
= wxAutomationInstance_CreateIfNeeded
) const;
339 Retrieves a property from this object, assumed to be a dispatch pointer, and
340 initialises @a obj with it.
341 To avoid having to deal with IDispatch pointers directly, use this function in
343 to GetProperty() when retrieving objects
345 Note that an IDispatch pointer is stored as a void* pointer in wxVariant
350 bool GetObject(wxAutomationObject
& obj
, const wxString
& property
,
352 wxVariant args
[] = NULL
) const;
356 Gets a property value from this object. The first form takes a property name,
358 arguments, and an array of variants. The second form takes a property name and
360 constant references to variants. Since the variant class has constructors for
362 data types, and C++ provides temporary objects automatically, both of the
364 are syntactically valid:
366 Note that @a property can contain dot-separated property names, to save the
368 needing to call GetProperty several times using several temporary objects.
370 wxVariant
GetProperty(const wxString
& property
, int noArgs
,
371 wxVariant args
[]) const;
372 const wxVariant
GetProperty(const wxString
& property
, ... ) const;
376 This function is a low-level implementation that allows access to the IDispatch
378 It is not meant to be called directly by the application, but is used by other
379 convenience functions.
382 The member function or property name.
384 Bitlist: may contain DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF,
387 Return value (ignored if there is no return value)
389 Number of arguments in args or ptrArgs.
391 If non-null, contains an array of variants.
393 If non-null, contains an array of constant pointers to variants.
395 @return @true if the operation was successful, @false otherwise.
397 @remarks Two types of argument array are provided, so that when possible
398 pointers are used for efficiency.
400 bool Invoke(const wxString
& member
, int action
,
401 wxVariant
& retValue
, int noArgs
,
403 const wxVariant
* ptrArgs
[] = 0) const;
407 Puts a property value into this object. The first form takes a property name,
409 arguments, and an array of variants. The second form takes a property name and
411 constant references to variants. Since the variant class has constructors for
413 data types, and C++ provides temporary objects automatically, both of the
415 are syntactically valid:
417 Note that @a property can contain dot-separated property names, to save the
419 needing to call GetProperty several times using several temporary objects.
421 bool PutProperty(const wxString
& property
, int noArgs
,
423 const bool PutProperty(const wxString
& property
, ... );
427 Sets the IDispatch pointer. This function does not check if there is already an
429 You may need to cast from IDispatch* to WXIDISPATCH* when calling this function.
431 void SetDispatchPtr(WXIDISPATCH
* dispatchPtr
);
434 Returns the locale identifier used in automation calls.
436 The default is LOCALE_SYSTEM_DEFAULT but the objects obtained by
437 GetObject() inherit the locale identifier from the one that created
442 LCID
GetLCID() const;
445 Sets the locale identifier to be used in automation calls performed by
448 The default value is LOCALE_SYSTEM_DEFAULT.
450 Notice that any automation objects created by this one inherit the same
455 void SetLCID(LCID lcid
);