Qt 4.8
Functions | Variables
qaxservermain.cpp File Reference
#include <qstringlist.h>
#include <qvector.h>
#include "qaxfactory.h"
#include <qt_windows.h>

Go to the source code of this file.

Functions

STDAPI DumpIDL (const QString &outfile, const QString &ver)
 
HRESULT GetClassObject (const GUID &clsid, const GUID &iid, void **ppUnk)
 
int __cdecl main (int, char **)
 
static DWORD WINAPI MonitorProc (void *pv)
 
void qax_shutDown ()
 
bool qax_startServer (QAxFactory::ServerType type)
 
bool qax_stopServer ()
 
bool qax_winEventFilter (void *message)
 
void qAxCleanup ()
 
QString qAxInit ()
 
ulong qAxLockCount ()
 
void __cdecl qWinMain (HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector< char *> &)
 
static bool StartMonitor ()
 
HRESULT UpdateRegistry (BOOL bRegister)
 
EXTERN_C int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int nShowCmd)
 

Variables

static DWORD * classRegistration = 0
 
QT_STATIC_CONST DWORD dwPause = 500
 
static DWORD dwThreadID
 
QT_STATIC_CONST DWORD dwTimeOut = 1000
 
static HANDLE hEventShutdown
 
static bool qAxActivity = false
 
HANDLE qAxInstance
 
bool qAxIsServer
 
wchar_t qAxModuleFilename [MAX_PATH]
 
bool qAxOutProcServer
 

Function Documentation

◆ DumpIDL()

STDAPI DumpIDL ( const QString outfile,
const QString ver 
)

Definition at line 1062 of file qaxserver.cpp.

Referenced by classIDL(), and WinMain().

1064 {
1065  qAxIsServer = false;
1066  QTextStream out;
1067  if (outfile.contains(QLatin1String("\\"))) {
1068  QString outpath = outfile.left(outfile.lastIndexOf(QLatin1String("\\")));
1069  QDir dir;
1070  dir.mkpath(outpath);
1071  }
1072  QFile file(outfile);
1073  file.remove();
1074 
1076  filebase = filebase.left(filebase.lastIndexOf(QLatin1Char('.')));
1077 
1078  QString appID = qAxFactory()->appID().toString().toUpper();
1079  if (QUuid(appID).isNull())
1080  return 1;
1081  STRIPCB(appID);
1082  QString typeLibID = qAxFactory()->typeLibID().toString().toUpper();
1083  if (QUuid(typeLibID).isNull())
1084  return 2;
1085  STRIPCB(typeLibID);
1086  QString typelib = filebase.right(filebase.length() - filebase.lastIndexOf(QLatin1String("\\"))-1);
1087 
1088  if (!file.open(QIODevice::WriteOnly))
1089  return -1;
1090 
1091  out.setDevice(&file);
1092 
1093  QString version(ver.unicode(), ver.length());
1094  while (version.count(QLatin1Char('.')) > 1) {
1095  int lastdot = version.lastIndexOf(QLatin1Char('.'));
1096  version = version.left(lastdot) + version.right(version.length() - lastdot - 1);
1097  }
1098  if (version.isEmpty())
1099  version = QLatin1String("1.0");
1100 
1101  QString idQRect(QUuid(CLSID_QRect).toString());
1102  STRIPCB(idQRect);
1103  QString idQSize(QUuid(CLSID_QSize).toString());
1104  STRIPCB(idQSize);
1105  QString idQPoint(QUuid(CLSID_QPoint).toString());
1106  STRIPCB(idQPoint);
1107 
1108  out << "/****************************************************************************" << endl;
1109  out << "** Interface definition generated for ActiveQt project" << endl;
1110  out << "**" << endl;
1111  out << "** '" << QString::fromWCharArray(qAxModuleFilename) << '\'' << endl;
1112  out << "**" << endl;
1113  out << "** Created: " << QDateTime::currentDateTime().toString() << endl;
1114  out << "**" << endl;
1115  out << "** WARNING! All changes made in this file will be lost!" << endl;
1116  out << "****************************************************************************/" << endl << endl;
1117 
1118  out << "import \"ocidl.idl\";" << endl;
1119  out << "#include <olectl.h>" << endl << endl;
1120 
1121  // dummy application to create widgets
1122  bool delete_qApp = false;
1123  if (!qApp) {
1124  int argc;
1125  (void)new QApplication(argc, 0);
1126  delete_qApp = true;
1127  }
1128 
1129  out << '[' << endl;
1130  out << "\tuuid(" << typeLibID << ")," << endl;
1131  out << "\tversion(" << version << ")," << endl;
1132  out << "\thelpstring(\"" << typelib << ' ' << version << " Type Library\")" << endl;
1133  out << ']' << endl;
1134  out << "library " << typelib << "Lib" << endl;
1135  out << '{' << endl;
1136  out << "\timportlib(\"stdole32.tlb\");" << endl;
1137  out << "\timportlib(\"stdole2.tlb\");" << endl << endl;
1138 
1141 
1142  out << "\t/************************************************************************" << endl;
1143  out << "\t** If this causes a compile error in MIDL you need to upgrade the" << endl;
1144  out << "\t** Platform SDK you are using. Download the SDK from msdn.microsoft.com" << endl;
1145  out << "\t** and make sure that both the system and the Visual Studio environment" << endl;
1146  out << "\t** use the correct files." << endl;
1147  out << "\t**" << endl;
1148 
1149 #ifndef Q_CC_BOR
1150 #if __REQUIRED_RPCNDR_H_VERSION__ < Q_REQUIRED_RPCNDR_H_VERSION
1151  out << "\t** Required version of MIDL could not be verified. QRect, QSize and QPoint" << endl;
1152  out << "\t** support needs an updated Platform SDK to be installed." << endl;
1153  out << "\t*************************************************************************" << endl;
1154 #else
1155  out << "\t************************************************************************/" << endl;
1156 #endif
1157 
1158  out << endl;
1159  out << "\t[uuid(" << idQRect << ")]" << endl;
1160  out << "\tstruct QRect {" << endl;
1161  out << "\t\tint left;" << endl;
1162  out << "\t\tint top;" << endl;
1163  out << "\t\tint right;" << endl;
1164  out << "\t\tint bottom;" << endl;
1165  out << "\t};" << endl << endl;
1166 
1167  out << "\t[uuid(" << idQSize << ")]" << endl;
1168  out << "\tstruct QSize {" << endl;
1169  out << "\t\tint width;" << endl;
1170  out << "\t\tint height;" << endl;
1171  out << "\t};" << endl << endl;
1172 
1173  out << "\t[uuid(" << idQPoint << ")]" << endl;
1174  out << "\tstruct QPoint {" << endl;
1175  out << "\t\tint x;" << endl;
1176  out << "\t\tint y;" << endl;
1177  out << "\t};" << endl;
1178 #if __REQUIRED_RPCNDR_H_VERSION__ < Q_REQUIRED_RPCNDR_H_VERSION
1179  out << "\t*/" << endl;
1180 #endif
1181 #else
1182  out << "\t** Custom data types not supported with Borland." << endl;
1183  out << "\t*************************************************************************" << endl;
1184 #endif
1185  out << endl;
1186 
1187  out << "\t/* Forward declaration of classes that might be used as parameters */" << endl << endl;
1188 
1189  int res = S_OK;
1190  for (key = keys.begin(); key != keys.end(); ++key) {
1191  QByteArray className = (*key).toLatin1();
1192  const QMetaObject *mo = qAxFactory()->metaObject(QString::fromLatin1(className.constData()));
1193  // We have meta object information for this type. Forward declare it.
1194  if (mo) {
1195  QByteArray cleanType = qax_clean_type(*key, mo).toLatin1();
1196  out << "\tcoclass " << cleanType << ';' << endl;
1197  subtypes.append(cleanType);
1198  qRegisterMetaType(cleanType, (void**)0);
1199  cleanType += '*';
1200  subtypes.append(cleanType);
1201  qRegisterMetaType(cleanType, (void**)0);
1202  }
1203  }
1204  out << endl;
1205 
1206  for (key = keys.begin(); key != keys.end(); ++key) {
1207  QByteArray className = (*key).toLatin1();
1208  const QMetaObject *mo = qAxFactory()->metaObject(QString::fromLatin1(className.constData()));
1209  // We have meta object information for this type. Define it.
1210  if (mo) {
1212  // It's not a control class, so it is actually a subtype. Define it.
1213  if (!o)
1214  res = classIDL(0, mo, QString::fromLatin1(className), false, out);
1215  delete o;
1216  }
1217  }
1218 
1219  out << endl;
1220  if (res != S_OK)
1221  goto ErrorInClass;
1222 
1223  for (key = keys.begin(); key != keys.end(); ++key) {
1224  QByteArray className = (*key).toLatin1();
1226  if (!o)
1227  continue;
1228  const QMetaObject *mo = o->metaObject();
1229  QAxBindable *bind = (QAxBindable*)o->qt_metacast("QAxBindable");
1230  bool isBindable = bind != 0;
1231 
1232  QByteArray cleanType = qax_clean_type(*key, mo).toLatin1();
1233  subtypes.append(cleanType);
1234  subtypes.append(cleanType + '*');
1235  res = classIDL(o, mo, QString::fromLatin1(className.constData()), isBindable, out);
1236  delete o;
1237  if (res != S_OK)
1238  break;
1239  }
1240 
1241  out << "};" << endl;
1242  out.flush();
1243 
1244 ErrorInClass:
1245  if (delete_qApp)
1246  delete qApp;
1247 
1248  if (res != S_OK) {
1249  file.close();
1250  file.remove();
1251  }
1252 
1253  return res;
1254 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static HRESULT classIDL(QObject *o, const QMetaObject *mo, const QString &className, bool isBindable, QTextStream &out)
Definition: qaxserver.cpp:749
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
Definition: qdir.cpp:1477
virtual QUuid typeLibID() const
Reimplement this function to return the ActiveX server&#39;s type library identifier. ...
Definition: qaxfactory.cpp:124
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QTextStream & endl(QTextStream &stream)
Writes &#39; &#39; to the stream and flushes the stream.
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
void setDevice(QIODevice *device)
Sets the current device to device.
The QAxBindable class provides an interface between a QWidget and an ActiveX client.
Definition: qaxbindable.h:60
QString qax_clean_type(const QString &type, const QMetaObject *mo)
Definition: qaxserver.cpp:191
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int qRegisterMetaType()
Call this function to register the type T.
Definition: qmetatype.h:234
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual QStringList featureList() const =0
Reimplement this function to return a list of the widgets (class names) supported by this factory...
QString toString() const
Returns the string representation of this QUuid.
Definition: quuid.cpp:512
QStringList keys
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
const char * className
Definition: qwizard.cpp:137
bool qAxIsServer
Definition: qaxserver.cpp:64
static QString toString(Register *reg, int type, bool *ok=0)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
CLSID CLSID_QSize
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
#define qApp
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
wchar_t qAxModuleFilename[MAX_PATH]
Definition: qaxserver.cpp:67
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual QUuid appID() const
Reimplement this function to return the ActiveX server&#39;s application identifier.
Definition: qaxfactory.cpp:138
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
#define STRIPCB(x)
Definition: qaxserver.cpp:683
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
int key
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
void flush()
Flushes any buffered data waiting to be written to the device.
static QList< QByteArray > subtypes
Definition: qaxserver.cpp:445
virtual const QMetaObject * metaObject(const QString &key) const =0
Reimplement this function to return the QMetaObject corresponding to key, or 0 if this factory doesn&#39;...
virtual QObject * createObject(const QString &key)=0
Reimplement this function to return a new object for key, or 0 if this factory doesn&#39;t support the va...
CLSID CLSID_QRect
QAxFactory * qAxFactory()
Definition: qaxserver.cpp:81
CLSID CLSID_QPoint
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ GetClassObject()

HRESULT GetClassObject ( const GUID clsid,
const GUID iid,
void **  ppUnk 
)

Referenced by qax_startServer().

◆ main()

int __cdecl main ( int  ,
char **   
)

Definition at line 46 of file qaxmain.cpp.

Referenced by qax_stopServer(), and WinMain().

47 {
50  QApplication app(argc, argv);
51  app.setQuitOnLastWindowClosed(false);
52 
53  return app.exec();
54 }
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
static bool startServer(ServerType type=MultipleInstances)
Starts the COM server with type and returns true if successful, otherwise returns false...
Definition: qaxfactory.h:115
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88

◆ MonitorProc()

static DWORD WINAPI MonitorProc ( void *  pv)
static

Definition at line 85 of file qaxservermain.cpp.

Referenced by StartMonitor().

86 {
87  while (1) {
88  WaitForSingleObject(hEventShutdown, INFINITE);
89  DWORD dwWait=0;
90  do {
91  qAxActivity = false;
92  dwWait = WaitForSingleObject(hEventShutdown, dwTimeOut);
93  } while (dwWait == WAIT_OBJECT_0);
94  // timed out
95  if (!qAxActivity && !qAxLockCount()) // if no activity let's really bail
96  break;
97  }
98  CloseHandle(hEventShutdown);
99  PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
100  PostQuitMessage(0);
101 
102  return 0;
103 }
ulong qAxLockCount()
Definition: qaxserver.cpp:180
#define WAIT_OBJECT_0
QT_STATIC_CONST DWORD dwTimeOut
static DWORD dwThreadID
static bool qAxActivity
static HANDLE hEventShutdown

◆ qax_shutDown()

void qax_shutDown ( )

Definition at line 117 of file qaxservermain.cpp.

Referenced by qAxUnlock().

118 {
119  qAxActivity = true;
120  if (hEventShutdown)
121  SetEvent(hEventShutdown); // tell monitor that we transitioned to zero
122 }
static bool qAxActivity
static HANDLE hEventShutdown

◆ qax_startServer()

bool qax_startServer ( QAxFactory::ServerType  type)

Definition at line 127 of file qaxservermain.cpp.

Referenced by QAxFactory::startServer().

128 {
129  if (qAxIsServer)
130  return true;
131 
132  const QStringList keys = qAxFactory()->featureList();
133  if (!keys.count())
134  return false;
135 
136  if (!qAxFactory()->isService())
137  StartMonitor();
138 
139  classRegistration = new DWORD[keys.count()];
140  int object = 0;
141  for (QStringList::ConstIterator key = keys.begin(); key != keys.end(); ++key, ++object) {
142  IUnknown* p = 0;
143  CLSID clsid = qAxFactory()->classID(*key);
144 
145  // Create a QClassFactory (implemented in qaxserverbase.cpp)
146  HRESULT hRes = GetClassObject(clsid, IID_IClassFactory, (void**)&p);
147  if (SUCCEEDED(hRes))
148  hRes = CoRegisterClassObject(clsid, p, CLSCTX_LOCAL_SERVER,
149  type == QAxFactory::MultipleInstances ? REGCLS_MULTIPLEUSE : REGCLS_SINGLEUSE,
150  classRegistration+object);
151  if (p)
152  p->Release();
153  }
154 
155  qAxIsServer = true;
156  return true;
157 }
int type
Definition: qmetatype.cpp:239
QAxFactory * qAxFactory()
Definition: qaxserver.cpp:81
bool qAxIsServer
Definition: qaxserver.cpp:64
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual QStringList featureList() const =0
Reimplement this function to return a list of the widgets (class names) supported by this factory...
QStringList keys
HRESULT GetClassObject(const GUID &clsid, const GUID &iid, void **ppUnk)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual bool isService() const
Reimplement this function to return true if the server is running as a persistent service (e...
Definition: qaxfactory.cpp:410
long HRESULT
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
int key
static bool StartMonitor()
virtual QUuid classID(const QString &key) const
Reimplement this function to return the class identifier for each key returned by the featureList() i...
Definition: qaxfactory.cpp:191
static DWORD * classRegistration

◆ qax_stopServer()

bool qax_stopServer ( )

Definition at line 162 of file qaxservermain.cpp.

Referenced by QAxFactory::startServer(), and QAxFactory::stopServer().

163 {
165  return true;
166 
167  qAxIsServer = false;
168 
169  const QStringList keys = qAxFactory()->featureList();
170  int object = 0;
171  for (QStringList::ConstIterator key = keys.begin(); key != keys.end(); ++key, ++object)
172  CoRevokeClassObject(classRegistration[object]);
173 
174  delete []classRegistration;
175  classRegistration = 0;
176 
177  Sleep(dwPause); //wait for any threads to finish
178 
179  return true;
180 }
QAxFactory * qAxFactory()
Definition: qaxserver.cpp:81
bool qAxIsServer
Definition: qaxserver.cpp:64
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
virtual QStringList featureList() const =0
Reimplement this function to return a list of the widgets (class names) supported by this factory...
QStringList keys
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
int key
QT_STATIC_CONST DWORD dwPause
static DWORD * classRegistration

◆ qax_winEventFilter()

bool qax_winEventFilter ( void *  message)

Definition at line 809 of file qaxserverbase.cpp.

Referenced by QClassFactory::CreateInstanceHelper().

810 {
811  MSG *pMsg = (MSG*)message;
812  if (pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST)
813  return false;
814 
815  bool ret = false;
816  QWidget *aqt = QWidget::find(pMsg->hwnd);
817  if (!aqt)
818  return ret;
819 
820  HWND baseHwnd = ::GetParent(aqt->winId());
821  QAxServerBase *axbase = 0;
822  while (!axbase && baseHwnd) {
823 #ifdef GWLP_USERDATA
824  axbase = (QAxServerBase*)GetWindowLongPtr(baseHwnd, GWLP_USERDATA);
825 #else
826  axbase = (QAxServerBase*)GetWindowLong(baseHwnd, GWL_USERDATA);
827 #endif
828 
829  baseHwnd = ::GetParent(baseHwnd);
830  }
831  if (!axbase)
832  return ret;
833 
834  HRESULT hres = axbase->TranslateAcceleratorW(pMsg);
835  return hres == S_OK;
836 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
struct tagMSG MSG
long HRESULT
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

◆ qAxCleanup()

void qAxCleanup ( )

Definition at line 139 of file qaxserver.cpp.

Referenced by WinMain().

140 {
141  if (!initCount)
142  qWarning("qAxInit/qAxCleanup mismatch");
143 
144  if (--initCount)
145  return;
146 
147  delete qax_factory;
148  qax_factory = 0;
149 
150  if (qAxTypeLibrary) {
151  qAxTypeLibrary->Release();
152  qAxTypeLibrary = 0;
153  }
154 
155  DeleteCriticalSection(&qAxModuleSection);
156 }
static CRITICAL_SECTION qAxModuleSection
Definition: qaxserver.cpp:102
ITypeLib * qAxTypeLibrary
Definition: qaxserver.cpp:66
Q_CORE_EXPORT void qWarning(const char *,...)
static int initCount
Definition: qaxserver.cpp:109
static QAxFactory * qax_factory
Definition: qaxserver.cpp:71

◆ qAxInit()

QString qAxInit ( )

Definition at line 111 of file qaxserver.cpp.

Referenced by UpdateRegistry(), and WinMain().

112 {
113  static QString libFile;
114 
115  if (initCount++)
116  return libFile;
117 
118  InitializeCriticalSection(&qAxModuleSection);
119 
121  libFile = libFile.toLower();
122  if (LoadTypeLibEx((wchar_t*)libFile.utf16(), REGKIND_NONE, &qAxTypeLibrary) == S_OK)
123  return libFile;
124 
125  int lastDot = libFile.lastIndexOf(QLatin1Char('.'));
126  libFile = libFile.left(lastDot) + QLatin1String(".tlb");
127  if (LoadTypeLibEx((wchar_t*)libFile.utf16(), REGKIND_NONE, &qAxTypeLibrary) == S_OK)
128  return libFile;
129 
130  lastDot = libFile.lastIndexOf(QLatin1Char('.'));
131  libFile = libFile.left(lastDot) + QLatin1String(".olb");
132  if (LoadTypeLibEx((wchar_t*)libFile.utf16(), REGKIND_NONE, &qAxTypeLibrary) == S_OK)
133  return libFile;
134 
135  libFile = QString();
136  return libFile;
137 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static CRITICAL_SECTION qAxModuleSection
Definition: qaxserver.cpp:102
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
ITypeLib * qAxTypeLibrary
Definition: qaxserver.cpp:66
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
wchar_t qAxModuleFilename[MAX_PATH]
Definition: qaxserver.cpp:67
static int initCount
Definition: qaxserver.cpp:109
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ qAxLockCount()

ulong qAxLockCount ( )

Definition at line 180 of file qaxserver.cpp.

Referenced by MonitorProc().

181 {
182  return qAxModuleRef;
183 }
static unsigned long qAxModuleRef
Definition: qaxserver.cpp:101

◆ qWinMain()

void __cdecl qWinMain ( HINSTANCE  ,
HINSTANCE  ,
LPSTR  ,
int  ,
int &  ,
QVector< char *> &   
)

Definition at line 170 of file qcoreapplication_win.cpp.

Referenced by qax_stopServer(), and WinMain().

177 {
178  static bool already_called = false;
179 
180  if (already_called) {
181  qWarning("Qt: Internal error: qWinMain should be called only once");
182  return;
183  }
184  already_called = true;
185  usingWinMain = true;
186 
187  // Install default debug handler
189 
190  // Create command line
191  argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc);
192 
193  appCmdShow = cmdShow;
194 
195  // Ignore Windows parameters
196  Q_UNUSED(instance);
197  Q_UNUSED(prevInstance);
198 }
Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str)
int appCmdShow
bool usingWinMain
Q_CORE_EXPORT void qWarning(const char *,...)
QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
Definition: qglobal.cpp:2698
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ StartMonitor()

static bool StartMonitor ( )
static

Definition at line 106 of file qaxservermain.cpp.

Referenced by qax_startServer().

107 {
108  dwThreadID = GetCurrentThreadId();
109  hEventShutdown = CreateEvent(0, false, false, 0);
110  if (hEventShutdown == 0)
111  return false;
112  DWORD dwThreadID;
113  HANDLE h = CreateThread(0, 0, MonitorProc, 0, 0, &dwThreadID);
114  return (h != NULL);
115 }
void * HANDLE
Definition: qnamespace.h:1671
static DWORD dwThreadID
static HANDLE hEventShutdown
static DWORD WINAPI MonitorProc(void *pv)

◆ UpdateRegistry()

HRESULT UpdateRegistry ( BOOL  bRegister)

Definition at line 208 of file qaxserver.cpp.

Referenced by WinMain().

209 {
210  qAxIsServer = false;
212  QString path = file.left(file.lastIndexOf(QLatin1Char('\\'))+1);
213  QString module = file.right(file.length() - path.length());
214  module = module.left(module.lastIndexOf(QLatin1Char('.')));
215 
216  const QString appId = qAxFactory()->appID().toString().toUpper();
217  const QString libId = qAxFactory()->typeLibID().toString().toUpper();
218 
219  QString libFile = qAxInit();
220  QString typeLibVersion;
221 
222  TLIBATTR *libAttr = 0;
223  if (qAxTypeLibrary)
224  qAxTypeLibrary->GetLibAttr(&libAttr);
225  if (!libAttr)
226  return SELFREG_E_TYPELIB;
227 
228  DWORD major = libAttr->wMajorVerNum;
229  DWORD minor = libAttr->wMinorVerNum;
230  typeLibVersion = QString::number((uint)major) + QLatin1Char('.') + QString::number((uint)minor);
231 
232  if (bRegister)
233  RegisterTypeLib(qAxTypeLibrary, (wchar_t*)libFile.utf16(), 0);
234  else
235  UnRegisterTypeLib(libAttr->guid, libAttr->wMajorVerNum, libAttr->wMinorVerNum, libAttr->lcid, libAttr->syskind);
236 
237  qAxTypeLibrary->ReleaseTLibAttr(libAttr);
238 
239  if (typeLibVersion.isEmpty())
240  typeLibVersion = QLatin1String("1.0");
241 
242  // check whether the user has permission to write to HKLM\Software\Classes
243  // if not, use HKCU\Software\Classes
244  QString keyPath(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Classes"));
246  if (!test.isWritable())
247  keyPath = QLatin1String("HKEY_CURRENT_USER\\Software\\Classes");
248 
250 
251  // we try to create the ActiveX widgets later on...
252  bool delete_qApp = false;
253  if (!qApp) {
254  int argc = 0;
255  (void)new QApplication(argc, 0);
256  delete_qApp = true;
257  }
258 
259  if (bRegister) {
260  if (qAxOutProcServer) {
261  settings.setValue(QLatin1String("/AppID/") + appId + QLatin1String("/."), module);
262  settings.setValue(QLatin1String("/AppID/") + module + QLatin1String(".EXE/AppID"), appId);
263  }
264 
266  for (QStringList::Iterator key = keys.begin(); key != keys.end(); ++key) {
267  QString className = *key;
268  QObject *object = qAxFactory()->createObject(className);
269  const QMetaObject *mo = qAxFactory()->metaObject(className);
270  const QString classId = qAxFactory()->classID(className).toString().toUpper();
271 
272  className = qax_clean_type(className, mo);
273 
274  if (object) { // don't register subobject classes
275  QString classVersion = mo ? QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("Version")).value()) : QString();
276  if (classVersion.isNull())
277  classVersion = QLatin1String("1.0");
278  bool insertable = mo && !qstricmp(mo->classInfo(mo->indexOfClassInfo("Insertable")).value(), "yes");
279  bool control = object->isWidgetType();
280  const QString classMajorVersion = classVersion.left(classVersion.indexOf(QLatin1Char('.')));
281  uint olemisc = OLEMISC_SETCLIENTSITEFIRST
282  |OLEMISC_ACTIVATEWHENVISIBLE
283  |OLEMISC_INSIDEOUT
284  |OLEMISC_CANTLINKINSIDE
285  |OLEMISC_RECOMPOSEONRESIZE;
286  if (!control)
287  olemisc |= OLEMISC_INVISIBLEATRUNTIME;
288  else if (object->findChild<QMenuBar*>() && !qax_disable_inplaceframe)
289  olemisc |= OLEMISC_WANTSTOMENUMERGE;
290 
291  settings.setValue(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion + QLatin1String("/."), className + QLatin1String(" Class"));
292  settings.setValue(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion + QLatin1String("/CLSID/."), classId);
293  if (insertable)
294  settings.setValue(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion + QLatin1String("/Insertable/."), QVariant(QLatin1String("")));
295 
296  settings.setValue(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1String("/."), className + QLatin1String(" Class"));
297  settings.setValue(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1String("/CLSID/."), classId);
298  settings.setValue(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1String("/CurVer/."), module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion);
299 
300  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/."), className + QLatin1String(" Class"));
301  if (file.endsWith(QLatin1String("exe"), Qt::CaseInsensitive))
302  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/AppID"), appId);
303  if (control)
304  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/Control/."), QVariant(QLatin1String("")));
305  if (insertable)
306  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/Insertable/."), QVariant(QLatin1String("")));
307  if (file.right(3).toLower() == QLatin1String("dll"))
308  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/InProcServer32/."), file);
309  else
310  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/LocalServer32/."),
311  QLatin1Char('\"') + file + QLatin1String("\" -activex"));
312  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/MiscStatus/."), control ? QLatin1String("1") : QLatin1String("0"));
313  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/MiscStatus/1/."), QString::number(olemisc));
314  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/Programmable/."), QVariant(QLatin1String("")));
315  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/ToolboxBitmap32/."), QLatin1Char('\"') +
316  file + QLatin1String("\", 101"));
317  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/TypeLib/."), libId); settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/Version/."), classVersion);
318  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/VersionIndependentProgID/."), module + QLatin1Char('.') + className);
319  settings.setValue(QLatin1String("/CLSID/") + classId + QLatin1String("/ProgID/."), module + QLatin1Char('.') + className + QLatin1Char('.') + classVersion.left(classVersion.indexOf(QLatin1Char('.'))));
320 
321  QString mime = QLatin1String(mo->classInfo(mo->indexOfClassInfo("MIME")).value());
322  if (!mime.isEmpty()) {
323  QStringList mimeTypes = mime.split(QLatin1Char(';'));
324  for (int m = 0; m < mimeTypes.count(); ++m) {
325  mime = mimeTypes.at(m);
326  if (mime.isEmpty())
327  continue;
328  QString extension;
329  while (mime.contains(QLatin1Char(':'))) {
330  extension = mime.mid(mime.lastIndexOf(QLatin1Char(':')) + 1);
331  mime = mime.left(mime.length() - extension.length() - 1);
332  // Prepend '.' before extension, if required.
333  extension = extension.trimmed();
334  if (extension[0] != QLatin1Char('.'))
335  extension = QLatin1Char('.') + extension;
336  }
337 
338  if (!extension.isEmpty()) {
339  settings.setValue(QLatin1Char('/') + extension + QLatin1String("/."), module + QLatin1Char('.') + className);
340  settings.setValue(QLatin1Char('/') + extension + QLatin1String("/Content Type"), mime);
341 
342  mime = mime.replace(QLatin1Char('/'), QLatin1Char('\\'));
343  settings.setValue(QLatin1String("/MIME/Database/Content Type/") + mime + QLatin1String("/CLSID"), classId);
344  settings.setValue(QLatin1String("/MIME/Database/Content Type/") + mime + QLatin1String("/Extension"), extension);
345  }
346  }
347  }
348 
349  delete object;
350  }
351 
352  qAxFactory()->registerClass(*key, &settings);
353  }
354  } else {
355  if (qAxOutProcServer) {
356  settings.remove(QLatin1String("/AppID/") + appId + QLatin1String("/."));
357  settings.remove(QLatin1String("/AppID/") + module + QLatin1String(".EXE"));
358  }
359  QStringList keys = qAxFactory()->featureList();
360  for (QStringList::Iterator key = keys.begin(); key != keys.end(); ++key) {
361  QString className = *key;
362  const QMetaObject *mo = qAxFactory()->metaObject(className);
363  const QString classId = qAxFactory()->classID(className).toString().toUpper();
364  className = qax_clean_type(className, mo);
365 
366  QString classVersion = mo ? QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("Version")).value()) : QString();
367  if (classVersion.isNull())
368  classVersion = QLatin1String("1.0");
369  const QString classMajorVersion = classVersion.left(classVersion.indexOf(QLatin1Char('.')));
370 
371  qAxFactory()->unregisterClass(*key, &settings);
372 
373  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion + QLatin1String("/CLSID/."));
374  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion + QLatin1String("/Insertable/."));
375  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion + QLatin1String("/."));
376  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1Char('.') + classMajorVersion);
377 
378  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1String("/CLSID/."));
379  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1String("/CurVer/."));
380  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className + QLatin1String("/."));
381  settings.remove(QLatin1Char('/') + module + QLatin1Char('.') + className);
382 
383  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/AppID"));
384  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/Control/."));
385  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/Insertable/."));
386  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/InProcServer32/."));
387  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/LocalServer32/."));
388  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/MiscStatus/1/."));
389  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/MiscStatus/."));
390  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/Programmable/."));
391  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/ToolboxBitmap32/."));
392  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/TypeLib/."));
393  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/Version/."));
394  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/VersionIndependentProgID/."));
395  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/ProgID/."));
396  settings.remove(QLatin1String("/CLSID/") + classId + QLatin1String("/."));
397  settings.remove(QLatin1String("/CLSID/") + classId);
398 
399  QString mime = QLatin1String(mo->classInfo(mo->indexOfClassInfo("MIME")).value());
400  if (!mime.isEmpty()) {
401  QStringList mimeTypes = mime.split(QLatin1Char(';'));
402  for (int m = 0; m < mimeTypes.count(); ++m) {
403  mime = mimeTypes.at(m);
404  if (mime.isEmpty())
405  continue;
406  QString extension;
407  while (mime.contains(QLatin1Char(':'))) {
408  extension = mime.mid(mime.lastIndexOf(QLatin1Char(':')) + 1);
409  mime = mime.left(mime.length() - extension.length() - 1);
410  // Prepend '.' before extension, if required.
411  extension = extension.trimmed();
412  if (extension[0] != QLatin1Char('.'))
413  extension.prepend(QLatin1Char('.'));
414  }
415  if (!extension.isEmpty()) {
416  settings.remove(QLatin1Char('/') + extension + QLatin1String("/Content Type"));
417  settings.remove(QLatin1Char('/') + extension + QLatin1String("/."));
418  settings.remove(QLatin1Char('/') + extension);
419  mime.replace(QLatin1Char('/'), QLatin1Char('\\'));
420  settings.remove(QLatin1String("/MIME/Database/Content Type/") + mime + QLatin1String("/Extension"));
421  settings.remove(QLatin1String("/MIME/Database/Content Type/") + mime + QLatin1String("/CLSID"));
422  settings.remove(QLatin1String("/MIME/Database/Content Type/") + mime + QLatin1String("/."));
423  settings.remove(QLatin1String("/MIME/Database/Content Type/") + mime);
424  }
425  }
426  }
427  }
428  }
429 
430  if (delete_qApp)
431  delete qApp;
432 
433  qAxCleanup();
434  if (settings.status() == QSettings::NoError)
435  return S_OK;
436  return SELFREG_E_CLASS;
437 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
virtual QUuid typeLibID() const
Reimplement this function to return the ActiveX server&#39;s type library identifier. ...
Definition: qaxfactory.cpp:124
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
QString qax_clean_type(const QString &type, const QMetaObject *mo)
Definition: qaxserver.cpp:191
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
void qAxCleanup()
Definition: qaxserver.cpp:139
QMetaClassInfo classInfo(int index) const
Returns the meta-data for the item of class information with the given index.
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
const char * mime
static QString keyPath(const QString &rKey)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
ITypeLib * qAxTypeLibrary
Definition: qaxserver.cpp:66
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual QStringList featureList() const =0
Reimplement this function to return a list of the widgets (class names) supported by this factory...
QString toString() const
Returns the string representation of this QUuid.
Definition: quuid.cpp:512
bool qAxOutProcServer
Definition: qaxserver.cpp:68
QStringList keys
const char * className
Definition: qwizard.cpp:137
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278
bool qAxIsServer
Definition: qaxserver.cpp:64
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define qApp
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
wchar_t qAxModuleFilename[MAX_PATH]
Definition: qaxserver.cpp:67
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual QUuid appID() const
Reimplement this function to return the ActiveX server&#39;s application identifier.
Definition: qaxfactory.cpp:138
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
T findChild(const QString &aName=QString()) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object.
Definition: qobject.h:158
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
int qstricmp(const char *str1, const char *str2)
A safe stricmp() function.
Definition: qbytearray.cpp:279
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
virtual void unregisterClass(const QString &key, QSettings *) const
Unregisters any additional values for the class key from the system registry using the settings objec...
Definition: qaxfactory.cpp:266
QString qAxInit()
Definition: qaxserver.cpp:111
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
bool qax_disable_inplaceframe
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
virtual const QMetaObject * metaObject(const QString &key) const =0
Reimplement this function to return the QMetaObject corresponding to key, or 0 if this factory doesn&#39;...
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
virtual QObject * createObject(const QString &key)=0
Reimplement this function to return a new object for key, or 0 if this factory doesn&#39;t support the va...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
QAxFactory * qAxFactory()
Definition: qaxserver.cpp:81
int indexOfClassInfo(const char *name) const
Finds class information item name and returns its index; otherwise returns -1.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual QUuid classID(const QString &key) const
Reimplement this function to return the class identifier for each key returned by the featureList() i...
Definition: qaxfactory.cpp:191
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
virtual void registerClass(const QString &key, QSettings *) const
Registers additional values for the class key in the system registry using the settings object...
Definition: qaxfactory.cpp:252

◆ WinMain()

EXTERN_C int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  ,
int  nShowCmd 
)

Definition at line 202 of file qaxservermain.cpp.

203 {
205 
206  qAxOutProcServer = true;
207  GetModuleFileName(0, qAxModuleFilename, MAX_PATH);
208  qAxInstance = hInstance;
209 
210  QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit();
211  QList<QByteArray> cmds = cmdParam.split(' ');
212  QByteArray unprocessed;
213 
214  int nRet = 0;
215  bool run = true;
216  bool runServer = false;
217  for (int i = 0; i < cmds.count(); ++i) {
218  QByteArray cmd = cmds.at(i).toLower();
219  if (cmd == "-activex" || cmd == "/activex" || cmd == "-embedding" || cmd == "/embedding") {
220  runServer = true;
221  } else if (cmd == "-unregserver" || cmd == "/unregserver") {
222  nRet = UpdateRegistry(false);
223  run = false;
224  break;
225  } else if (cmd == "-regserver" || cmd == "/regserver") {
226  nRet = UpdateRegistry(true);
227  run = false;
228  break;
229  } else if (cmd == "-dumpidl" || cmd == "/dumpidl") {
230  ++i;
231  if (i < cmds.count()) {
232  QByteArray outfile = cmds.at(i);
233  ++i;
234  QByteArray version;
235  if (i < cmds.count() && (cmds.at(i) == "-version" || cmds.at(i) == "/version")) {
236  ++i;
237  if (i < cmds.count())
238  version = cmds.at(i);
239  else
240  version = "1.0";
241  }
242 
243  nRet = DumpIDL(QString::fromLatin1(outfile.constData()), QString::fromLatin1(version.constData()));
244  } else {
245  qWarning("Wrong commandline syntax: <app> -dumpidl <idl file> [-version <x.y.z>]");
246  }
247  run = false;
248  break;
249  } else {
250  unprocessed += cmds.at(i) + ' ';
251  }
252  }
253 
254  if (run) {
255  HRESULT hRes = CoInitialize(0);
256 
257  int argc;
258  QVector<char*> argv(8);
259  qWinMain(hInstance, hPrevInstance, unprocessed.data(), nShowCmd, argc, argv);
260  qAxInit();
261  if (runServer)
263  nRet = ::main(argc, argv.data());
265  qAxCleanup();
266  CoUninitialize();
267 
268  }
269 
270  return nRet;
271 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
void qAxCleanup()
Definition: qaxserver.cpp:139
STDAPI DumpIDL(const QString &outfile, const QString &ver)
Definition: qaxserver.cpp:1062
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static bool stopServer()
Stops the COM server and returns true if successful, otherwise returns false.
Definition: qaxfactory.h:123
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray toLower() const
Returns a lowercase copy of the byte array.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
#define CoInitialize(x)
void __cdecl qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector< char *> &)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
QString qAxInit()
Definition: qaxserver.cpp:111
wchar_t qAxModuleFilename[MAX_PATH]
Definition: qaxserver.cpp:67
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
bool qAxOutProcServer
Definition: qaxserver.cpp:68
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays...
long HRESULT
static bool startServer(ServerType type=MultipleInstances)
Starts the COM server with type and returns true if successful, otherwise returns false...
Definition: qaxfactory.h:115
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
QFuture< T > run(Function function,...)
HANDLE qAxInstance
Definition: qaxserver.cpp:65
int __cdecl main(int, char **)
Definition: qaxmain.cpp:46
HRESULT UpdateRegistry(BOOL bRegister)
Definition: qaxserver.cpp:208

Variable Documentation

◆ classRegistration

DWORD* classRegistration = 0
static

Definition at line 52 of file qaxservermain.cpp.

Referenced by qax_startServer(), and qax_stopServer().

◆ dwPause

QT_STATIC_CONST DWORD dwPause = 500

Definition at line 59 of file qaxservermain.cpp.

Referenced by qax_stopServer().

◆ dwThreadID

DWORD dwThreadID
static

Definition at line 53 of file qaxservermain.cpp.

Referenced by MonitorProc(), qt_adopted_thread_watcher_function(), and StartMonitor().

◆ dwTimeOut

QT_STATIC_CONST DWORD dwTimeOut = 1000

Definition at line 58 of file qaxservermain.cpp.

Referenced by MonitorProc().

◆ hEventShutdown

HANDLE hEventShutdown
static

Definition at line 55 of file qaxservermain.cpp.

Referenced by MonitorProc(), qax_shutDown(), and StartMonitor().

◆ qAxActivity

bool qAxActivity = false
static

Definition at line 54 of file qaxservermain.cpp.

Referenced by MonitorProc(), and qax_shutDown().

◆ qAxInstance

HANDLE qAxInstance

Definition at line 65 of file qaxserver.cpp.

Referenced by WinMain().

◆ qAxIsServer

bool qAxIsServer

Definition at line 64 of file qaxserver.cpp.

Referenced by DumpIDL(), qax_startServer(), qax_stopServer(), and UpdateRegistry().

◆ qAxModuleFilename

wchar_t qAxModuleFilename[MAX_PATH]

Definition at line 67 of file qaxserver.cpp.

Referenced by DumpIDL(), qAxInit(), UpdateRegistry(), and WinMain().

◆ qAxOutProcServer

bool qAxOutProcServer

Definition at line 68 of file qaxserver.cpp.

Referenced by WinMain().