$szTitle = "wxautomationobject"; include "./_header.inc"; ?>
the wxautomationobject class represents an ole automation object containing a single data member, an idispatch pointer. it contains a number of functions that make it easy to perform automation operations, and set and get properties. the class makes heavy use of the wxvariant class.
the usage of these classes is quite close to ole automation usage in visual basic. the api is high-level, and the application can specify multiple properties in a single string. the following example gets the current excel instance, and if it exists, makes the active cell bold.
wxautomationobject excelobject;
if (excelobject.getinstance("excel.application"))
excelobject.putproperty("activecell.font.bold", true);
note that this class obviously works under windows only.
derived from
include files
<wx/msw/ole/automtn.h>
see also
members
wxautomationobject::wxautomationobject
wxautomationobject::~wxautomationobject
wxautomationobject::callmethod
wxautomationobject::createinstance
wxautomationobject::getdispatchptr
wxautomationobject::getinstance
wxautomationobject::getobject
wxautomationobject::getproperty
wxautomationobject::invoke
wxautomationobject::putproperty
wxautomationobject::setdispatchptr
wxautomationobject(wxidispatch* dispatchptr = null)
constructor, taking an optional idispatch pointer which will be released when the object is deleted.
~wxautomationobject()
destructor. if the internal idispatch pointer is non-null, it will be released.
wxvariant callmethod(const wxstring& method, int noargs, wxvariant args[]) const
wxvariant callmethod(const wxstring& method, ...) const
calls an automation method for this object. the first form takes a method name, number of arguments, and an array of variants. the second form takes a method name and zero to six constant references to variants. since the variant class has constructors for the basic data types, and c++ provides temporary objects automatically, both of the following lines are syntactically valid:
wxvariant res = obj.callmethod("sum", wxvariant(1.2), wxvariant(3.4));
wxvariant res = obj.callmethod("sum", 1.2, 3.4);
note that method can contain dot-separated property names, to save the application needing to call getproperty several times using several temporary objects. for example:
object.callmethod("activecell.font.showdialog", "my caption");
bool createinstance(const wxstring& classid) const
creates a new object based on the class id, returning true if the object was successfully created, or false if not.
idispatch* getdispatchptr() const
gets the idispatch pointer.
bool getinstance(const wxstring& classid) const
retrieves the current object associated with a class id, and attaches the idispatch pointer to this object. returns true if a pointer was successfully retrieved, false otherwise.
note that this cannot cope with two instances of a given ole object being active simultaneously, such as two copies of excel running. which object is referenced cannot currently be specified.
bool getobject(wxautomationobject&obj const wxstring& property, int noargs = 0, wxvariant args[] = null) const
retrieves a property from this object, assumed to be a dispatch pointer, and initialises obj with it. to avoid having to deal with idispatch pointers directly, use this function in preference to wxautomationobject::getproperty when retrieving objects from other objects.
note that an idispatch pointer is stored as a void* pointer in wxvariant objects.
see also
wxautomationobject::getproperty
wxvariant getproperty(const wxstring& property, int noargs, wxvariant args[]) const
wxvariant getproperty(const wxstring& property, ...) const
gets a property value from this object. the first form takes a property name, number of arguments, and an array of variants. the second form takes a property name and zero to six constant references to variants. since the variant class has constructors for the basic data types, and c++ provides temporary objects automatically, both of the following lines are syntactically valid:
wxvariant res = obj.getproperty("range", wxvariant("a1"));
wxvariant res = obj.getproperty("range", "a1");
note that property can contain dot-separated property names, to save the application needing to call getproperty several times using several temporary objects.
bool invoke(const wxstring& member, int action, wxvariant& retvalue, int noargs, wxvariant args[], const wxvariant* ptrargs[] = 0) const
this function is a low-level implementation that allows access to the idispatch invoke function. it is not meant to be called directly by the application, but is used by other convenience functions.
parameters
member
action
retvalue
noargs
args
ptrargs
return value
true if the operation was successful, false otherwise.
remarks
two types of argument array are provided, so that when possible pointers are used for efficiency.
bool putproperty(const wxstring& property, int noargs, wxvariant args[]) const
bool putproperty(const wxstring& property, ...)
puts a property value into this object. the first form takes a property name, number of arguments, and an array of variants. the second form takes a property name and zero to six constant references to variants. since the variant class has constructors for the basic data types, and c++ provides temporary objects automatically, both of the following lines are syntactically valid:
obj.putproperty("value", wxvariant(23));
obj.putproperty("value", 23);
note that property can contain dot-separated property names, to save the application needing to call getproperty several times using several temporary objects.
void setdispatchptr(wxidispatch* dispatchptr)
sets the idispatch pointer. this function does not check if there is already an idispatch pointer.
you may need to cast from idispatch* to wxidispatch* when calling this function.
include "./_footer.inc"; ?>