source: trunk/doc/src/snippets/code/doc_src_qaxserver.qdoc@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 3.4 KB
Line 
1//! [0]
2TEMPLATE = app
3CONFIG += qaxserver
4
5RC_FILE = qaxserver.rc
6...
7//! [0]
8
9
10//! [1]
11TEMPLATE = lib
12CONFIG += qaxserver dll
13
14DEF_FILE = qaxserver.def
15RC_FILE = qaxserver.rc
16...
17//! [1]
18
19
20//! [2]
21TEMPLATE = lib
22VERSION = 2.5
23...
24//! [2]
25
26
27//! [3]
28#include <QWidget>
29
30class MyActiveX : public QWidget
31{
32 Q_OBJECT
33//! [3]
34
35
36//! [4]
37Q_CLASSINFO("ClassID", "{1D9928BD-4453-4bdd-903D-E525ED17FDE5}")
38Q_CLASSINFO("InterfaceID", "{99F6860E-2C5A-42ec-87F2-43396F4BE389}")
39Q_CLASSINFO("EventsID", "{0A3E9F27-E4F1-45bb-9E47-63099BCCD0E3}")
40//! [4]
41
42
43//! [5]
44Q_PROPERTY(int value READ value WRITE setValue)
45//! [5]
46
47
48//! [6]
49public:
50 MyActiveX(QWidget *parent = 0)
51 ...
52
53 int value() const;
54
55public slots:
56 void setValue(int v);
57 ...
58
59signals:
60 void valueChange(int v);
61 ...
62
63};
64//! [6]
65
66
67//! [7]
68#include <QAxBindable>
69#include <QWidget>
70
71class MyActiveX : public QWidget, public QAxBindable
72{
73 Q_OBJECT
74//! [7]
75
76
77//! [8]
78QAXFACTORY_BEGIN("{ad90301a-849e-4e8b-9a91-0a6dc5f6461f}",
79 "{a8f21901-7ff7-4f6a-b939-789620c03d83}")
80 QAXCLASS(MyWidget)
81 QAXCLASS(MyWidget2)
82 QAXTYPE(MySubType)
83QAXFACTORY_END()
84//! [8]
85
86
87//! [9]
88#include <QApplication>
89#include <QAxFactory>
90
91int main(int argc, char *argv[])
92{
93 QApplication app(argc, argv);
94 if (!QAxFactory::isServer()) {
95 // create and show main window
96 }
97 return app.exec();
98}
99//! [9]
100
101
102//! [10]
103MyFactory(const QUuid &, const QUuid &);
104//! [10]
105
106
107//! [11]
108HMODULE dll = LoadLibrary("myserver.dll");
109typedef HRESULT(__stdcall *DllRegisterServerProc)();
110DllRegisterServerProc DllRegisterServer =
111 (DllRegisterServerProc)GetProcAddress(dll, "DllRegisterServer");
112
113HRESULT res = E_FAIL;
114if (DllRegisterServer)
115 res = DllRegisterServer();
116if (res != S_OK)
117 // error handling
118//! [11]
119
120
121//! [12]
122cabarc N simpleax.cab simpleax.exe simple.inf
123//! [12]
124
125
126//! [13]
127<object ID="MyActiveX1" CLASSID="CLSID:ad90301a-849e-4e8b-9a91-0a6dc5f6461f">
128 ...
129<\object>
130//! [13]
131
132
133//! [14]
134<object ID=...>
135 <param name="name" value="value">
136<\object>
137//! [14]
138
139
140//! [15]
141class MyActiveX : public QWidget
142{
143 Q_OBJECT
144 Q_CLASSINFO("Version", "2.0")
145 Q_CLASSINFO("ClassID", "{7a4cffd8-cbcd-4ae9-ae7e-343e1e5710df}")
146 Q_CLASSINFO("InterfaceID", "{6fb035bf-8019-48d8-be51-ef05427d8994}")
147 Q_CLASSINFO("EventsID", "{c42fffdf-6557-47c9-817a-2da2228bc29c}")
148 Q_CLASSINFO("Insertable", "yes")
149 Q_CLASSINFO("ToSuperClass", "MyActiveX")
150 Q_PROPERTY(...)
151
152public:
153 MyActiveX(QWidget *parent = 0);
154
155 ...
156};
157//! [15]
158
159
160//! [16]
161class MyLicensedControl : public QWidget
162{
163 Q_OBJECT
164 Q_CLASSINFO("LicenseKey", "<key string>")
165 ...
166};
167//! [16]
168
169
170//! [17]
171class AxImpl : public QAxAggregated, public ISomeCOMInterface
172{
173public:
174 AxImpl() {}
175
176 long queryInterface(const QUuid &iid, void **iface);
177
178 // IUnknown
179 QAXAGG_IUNKNOWN
180
181 // ISomeCOMInterface
182 ...
183}
184//! [17]
185
186
187//! [18]
188long AxImpl::queryInterface(const QUuid &iid, void **iface)
189{
190 *iface = 0;
191 if (iid == IID_ISomeCOMInterface)
192 *iface = (ISomeCOMInterface *)this;
193 else
194 return E_NOINTERFACE;
195
196 AddRef();
197 return S_OK;
198}
199//! [18]
200
201
202//! [19]
203HRESULT AxImpl::QueryInterface(REFIID iid, void **iface)
204{
205 return controllingUnknown()->QueryInterface(iid, iface);
206}
207//! [19]
208
209
210//! [20]
211class MyActiveX : public QWidget, public QAxBindable
212{
213 Q_OBJECT
214
215public:
216 MyActiveX(QWidget *parent);
217
218 QAxAggregated *createAggregate()
219 {
220 return new AxImpl();
221 }
222};
223//! [20]
Note: See TracBrowser for help on using the repository browser.