]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/ole/automtn.h
no message
[wxWidgets.git] / include / wx / msw / ole / automtn.h
CommitLineData
e8b6d59d
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: automtn.h
3// Purpose: OLE automation utilities
4// Author: Julian Smart
5// Modified by:
6// Created: 11/6/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998, Julian Smart
9// Licence: wxWindows Licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma interface "automtn.h"
14#endif
15
16#ifndef _WX_AUTOMTN_H_
17#define _WX_AUTOMTN_H_
18
19#include "wx/object.h"
20#include "wx/variant.h"
21
22typedef void WXIDISPATCH;
23typedef unsigned short* WXBSTR;
24
25/*
26 * wxAutomationObject
27 * Wraps up an IDispatch pointer and invocation; does variant conversion.
28 */
29
30class wxAutomationObject: public wxObject
31{
32public:
33 wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL);
34 ~wxAutomationObject();
35
36 // Set/get dispatch pointer
37 inline void SetDispatchPtr(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; };
38 inline WXIDISPATCH* GetDispatchPtr() const { return m_dispatchPtr; }
39
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;
43
44 // Get a dispatch pointer from a new instance of the the class
45 bool CreateInstance(const wxString& classId) const;
46
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;
51
52 // Invoke a member function
53 wxVariant CallMethod(const wxString& method, int noArgs, wxVariant args[]);
54
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);
60
61 // Get/Put property
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);
67
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);
73
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;
79
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;
83
84 // Convert variants
85 static bool ConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant) ;
86 static bool ConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant) ;
87
88public:
89 WXIDISPATCH* m_dispatchPtr;
90};
91
92// wrapper around BSTR type (by Vadim Zeitlin)
93
94class BasicString
95{
96public:
97 // ctors & dtor
98 BasicString(const char *sz);
99 ~BasicString();
100
101 // accessors
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); }
106
107private:
108 // @@@ not implemented (but should be)
109 BasicString(const BasicString&);
110 BasicString& operator=(const BasicString&);
111
112 OLECHAR *m_wzBuf; // actual string
113};
114
115#endif
116 // _WX_AUTOMTN_H_