[561] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
| 8 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
| 10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
[561] | 11 | **
|
---|
[846] | 12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
| 13 | ** modification, are permitted provided that the following conditions are
|
---|
| 14 | ** met:
|
---|
| 15 | ** * Redistributions of source code must retain the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | ** notice, this list of conditions and the following disclaimer in
|
---|
| 19 | ** the documentation and/or other materials provided with the
|
---|
| 20 | ** distribution.
|
---|
| 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
| 22 | ** the names of its contributors may be used to endorse or promote
|
---|
| 23 | ** products derived from this software without specific prior written
|
---|
| 24 | ** permission.
|
---|
[561] | 25 | **
|
---|
[846] | 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
[561] | 37 | ** $QT_END_LICENSE$
|
---|
| 38 | **
|
---|
| 39 | ****************************************************************************/
|
---|
| 40 |
|
---|
[2] | 41 | //! [0]
|
---|
| 42 | TEMPLATE = app
|
---|
| 43 | CONFIG += qaxserver
|
---|
| 44 |
|
---|
| 45 | RC_FILE = qaxserver.rc
|
---|
| 46 | ...
|
---|
| 47 | //! [0]
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | //! [1]
|
---|
| 51 | TEMPLATE = lib
|
---|
| 52 | CONFIG += qaxserver dll
|
---|
| 53 |
|
---|
| 54 | DEF_FILE = qaxserver.def
|
---|
| 55 | RC_FILE = qaxserver.rc
|
---|
| 56 | ...
|
---|
| 57 | //! [1]
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | //! [2]
|
---|
| 61 | TEMPLATE = lib
|
---|
| 62 | VERSION = 2.5
|
---|
| 63 | ...
|
---|
| 64 | //! [2]
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | //! [3]
|
---|
| 68 | #include <QWidget>
|
---|
| 69 |
|
---|
| 70 | class MyActiveX : public QWidget
|
---|
| 71 | {
|
---|
| 72 | Q_OBJECT
|
---|
| 73 | //! [3]
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | //! [4]
|
---|
| 77 | Q_CLASSINFO("ClassID", "{1D9928BD-4453-4bdd-903D-E525ED17FDE5}")
|
---|
| 78 | Q_CLASSINFO("InterfaceID", "{99F6860E-2C5A-42ec-87F2-43396F4BE389}")
|
---|
| 79 | Q_CLASSINFO("EventsID", "{0A3E9F27-E4F1-45bb-9E47-63099BCCD0E3}")
|
---|
| 80 | //! [4]
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | //! [5]
|
---|
| 84 | Q_PROPERTY(int value READ value WRITE setValue)
|
---|
| 85 | //! [5]
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | //! [6]
|
---|
| 89 | public:
|
---|
| 90 | MyActiveX(QWidget *parent = 0)
|
---|
| 91 | ...
|
---|
| 92 |
|
---|
| 93 | int value() const;
|
---|
| 94 |
|
---|
| 95 | public slots:
|
---|
| 96 | void setValue(int v);
|
---|
| 97 | ...
|
---|
| 98 |
|
---|
| 99 | signals:
|
---|
| 100 | void valueChange(int v);
|
---|
| 101 | ...
|
---|
| 102 |
|
---|
| 103 | };
|
---|
| 104 | //! [6]
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | //! [7]
|
---|
| 108 | #include <QAxBindable>
|
---|
| 109 | #include <QWidget>
|
---|
| 110 |
|
---|
| 111 | class MyActiveX : public QWidget, public QAxBindable
|
---|
| 112 | {
|
---|
| 113 | Q_OBJECT
|
---|
| 114 | //! [7]
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | //! [8]
|
---|
| 118 | QAXFACTORY_BEGIN("{ad90301a-849e-4e8b-9a91-0a6dc5f6461f}",
|
---|
| 119 | "{a8f21901-7ff7-4f6a-b939-789620c03d83}")
|
---|
| 120 | QAXCLASS(MyWidget)
|
---|
| 121 | QAXCLASS(MyWidget2)
|
---|
| 122 | QAXTYPE(MySubType)
|
---|
| 123 | QAXFACTORY_END()
|
---|
| 124 | //! [8]
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | //! [9]
|
---|
| 128 | #include <QApplication>
|
---|
| 129 | #include <QAxFactory>
|
---|
| 130 |
|
---|
| 131 | int main(int argc, char *argv[])
|
---|
| 132 | {
|
---|
| 133 | QApplication app(argc, argv);
|
---|
| 134 | if (!QAxFactory::isServer()) {
|
---|
| 135 | // create and show main window
|
---|
| 136 | }
|
---|
| 137 | return app.exec();
|
---|
| 138 | }
|
---|
| 139 | //! [9]
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | //! [10]
|
---|
| 143 | MyFactory(const QUuid &, const QUuid &);
|
---|
| 144 | //! [10]
|
---|
| 145 |
|
---|
| 146 |
|
---|
| 147 | //! [11]
|
---|
| 148 | HMODULE dll = LoadLibrary("myserver.dll");
|
---|
| 149 | typedef HRESULT(__stdcall *DllRegisterServerProc)();
|
---|
| 150 | DllRegisterServerProc DllRegisterServer =
|
---|
| 151 | (DllRegisterServerProc)GetProcAddress(dll, "DllRegisterServer");
|
---|
| 152 |
|
---|
| 153 | HRESULT res = E_FAIL;
|
---|
| 154 | if (DllRegisterServer)
|
---|
| 155 | res = DllRegisterServer();
|
---|
| 156 | if (res != S_OK)
|
---|
| 157 | // error handling
|
---|
| 158 | //! [11]
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | //! [12]
|
---|
| 162 | cabarc N simpleax.cab simpleax.exe simple.inf
|
---|
| 163 | //! [12]
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 | //! [13]
|
---|
| 167 | <object ID="MyActiveX1" CLASSID="CLSID:ad90301a-849e-4e8b-9a91-0a6dc5f6461f">
|
---|
| 168 | ...
|
---|
| 169 | <\object>
|
---|
| 170 | //! [13]
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | //! [14]
|
---|
| 174 | <object ID=...>
|
---|
| 175 | <param name="name" value="value">
|
---|
| 176 | <\object>
|
---|
| 177 | //! [14]
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | //! [15]
|
---|
| 181 | class MyActiveX : public QWidget
|
---|
| 182 | {
|
---|
| 183 | Q_OBJECT
|
---|
| 184 | Q_CLASSINFO("Version", "2.0")
|
---|
| 185 | Q_CLASSINFO("ClassID", "{7a4cffd8-cbcd-4ae9-ae7e-343e1e5710df}")
|
---|
| 186 | Q_CLASSINFO("InterfaceID", "{6fb035bf-8019-48d8-be51-ef05427d8994}")
|
---|
| 187 | Q_CLASSINFO("EventsID", "{c42fffdf-6557-47c9-817a-2da2228bc29c}")
|
---|
| 188 | Q_CLASSINFO("Insertable", "yes")
|
---|
| 189 | Q_CLASSINFO("ToSuperClass", "MyActiveX")
|
---|
| 190 | Q_PROPERTY(...)
|
---|
| 191 |
|
---|
| 192 | public:
|
---|
| 193 | MyActiveX(QWidget *parent = 0);
|
---|
| 194 |
|
---|
| 195 | ...
|
---|
| 196 | };
|
---|
| 197 | //! [15]
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | //! [16]
|
---|
| 201 | class MyLicensedControl : public QWidget
|
---|
| 202 | {
|
---|
| 203 | Q_OBJECT
|
---|
| 204 | Q_CLASSINFO("LicenseKey", "<key string>")
|
---|
| 205 | ...
|
---|
| 206 | };
|
---|
| 207 | //! [16]
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | //! [17]
|
---|
| 211 | class AxImpl : public QAxAggregated, public ISomeCOMInterface
|
---|
| 212 | {
|
---|
| 213 | public:
|
---|
| 214 | AxImpl() {}
|
---|
| 215 |
|
---|
| 216 | long queryInterface(const QUuid &iid, void **iface);
|
---|
| 217 |
|
---|
| 218 | // IUnknown
|
---|
| 219 | QAXAGG_IUNKNOWN
|
---|
| 220 |
|
---|
| 221 | // ISomeCOMInterface
|
---|
| 222 | ...
|
---|
| 223 | }
|
---|
| 224 | //! [17]
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 | //! [18]
|
---|
| 228 | long AxImpl::queryInterface(const QUuid &iid, void **iface)
|
---|
| 229 | {
|
---|
| 230 | *iface = 0;
|
---|
| 231 | if (iid == IID_ISomeCOMInterface)
|
---|
| 232 | *iface = (ISomeCOMInterface *)this;
|
---|
| 233 | else
|
---|
| 234 | return E_NOINTERFACE;
|
---|
| 235 |
|
---|
| 236 | AddRef();
|
---|
| 237 | return S_OK;
|
---|
| 238 | }
|
---|
| 239 | //! [18]
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | //! [19]
|
---|
| 243 | HRESULT AxImpl::QueryInterface(REFIID iid, void **iface)
|
---|
| 244 | {
|
---|
| 245 | return controllingUnknown()->QueryInterface(iid, iface);
|
---|
| 246 | }
|
---|
| 247 | //! [19]
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 | //! [20]
|
---|
| 251 | class MyActiveX : public QWidget, public QAxBindable
|
---|
| 252 | {
|
---|
| 253 | Q_OBJECT
|
---|
| 254 |
|
---|
| 255 | public:
|
---|
| 256 | MyActiveX(QWidget *parent);
|
---|
| 257 |
|
---|
| 258 | QAxAggregated *createAggregate()
|
---|
| 259 | {
|
---|
| 260 | return new AxImpl();
|
---|
| 261 | }
|
---|
| 262 | };
|
---|
| 263 | //! [20]
|
---|