Qt 4.8
Functions | Variables
qaxserverdll.cpp File Reference
#include <qapplication.h>
#include <qwidget.h>
#include <qt_windows.h>

Go to the source code of this file.

Functions

STDAPI DllCanUnloadNow ()
 
STDAPI DllGetClassObject (const GUID &clsid, const GUID &iid, void **ppv)
 
EXTERN_C BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved)
 
STDAPI DllRegisterServer ()
 
STDAPI DllUnregisterServer ()
 
HRESULT GetClassObject (const GUID &clsid, const GUID &iid, void **ppUnk)
 
void qAxCleanup ()
 
QString qAxInit ()
 
unsigned long qAxLockCount ()
 
HRESULT UpdateRegistry (int bRegister)
 

Variables

HHOOK qax_hhook = 0
 
bool qax_ownQApp = false
 
HANDLE qAxInstance
 
bool qAxIsServer
 
wchar_t qAxModuleFilename [MAX_PATH]
 
static uint qAxThreadId = 0
 
ITypeLib * qAxTypeLibrary
 

Function Documentation

◆ DllCanUnloadNow()

STDAPI DllCanUnloadNow ( )

Definition at line 89 of file qaxserverdll.cpp.

90 {
91  if (GetCurrentThreadId() != qAxThreadId)
92  return S_FALSE;
93  if (qAxLockCount())
94  return S_FALSE;
95  if (!qax_ownQApp)
96  return S_OK;
97 
98  // check if qApp still runs widgets (in other DLLs)
99  QWidgetList widgets = qApp->allWidgets();
100  int count = widgets.count();
101  for (int w = 0; w < widgets.count(); ++w) {
102  // remove all Qt generated widgets
103  QWidget *widget = widgets.at(w);
104  if (widget->windowType() == Qt::Desktop || widget->objectName() == QLatin1String("Qt internal tablet widget"))
105  count--;
106  }
107  if (count)
108  return S_FALSE;
109 
110  // no widgets left - destroy qApp
111  if (qax_hhook)
112  UnhookWindowsHookEx(qax_hhook);
113 
114  delete qApp;
115  qax_ownQApp = false;
116 
117  // never allow unloading - safety net for Internet Explorer
118  return S_FALSE;
119 }
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
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
static uint qAxThreadId
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
HHOOK qax_hhook
QString objectName() const
unsigned long qAxLockCount()
Definition: qaxserver.cpp:180
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition: qwidget.h:937
bool qax_ownQApp
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ DllGetClassObject()

STDAPI DllGetClassObject ( const GUID clsid,
const GUID iid,
void **  ppv 
)

Definition at line 76 of file qaxserverdll.cpp.

77 {
78  if (!qAxThreadId)
79  qAxThreadId = GetCurrentThreadId();
80  else if (GetCurrentThreadId() != qAxThreadId)
81  return E_FAIL;
82 
83  GetClassObject(clsid, iid, ppv);
84  if (!*ppv)
85  return CLASS_E_CLASSNOTAVAILABLE;
86  return S_OK;
87 }
static uint qAxThreadId
HRESULT GetClassObject(const GUID &clsid, const GUID &iid, void **ppUnk)

◆ DllMain()

EXTERN_C BOOL WINAPI DllMain ( HINSTANCE  hInstance,
DWORD  dwReason,
LPVOID  lpvReserved 
)

Definition at line 122 of file qaxserverdll.cpp.

123 {
124  GetModuleFileName(hInstance, qAxModuleFilename, MAX_PATH);
125  qAxInstance = hInstance;
126  qAxIsServer = true;
127 
128  if (dwReason == DLL_PROCESS_ATTACH) {
129  DisableThreadLibraryCalls(hInstance);
130  qAxInit();
131  } else if (dwReason == DLL_PROCESS_DETACH) {
132  qAxCleanup();
133  }
134 
135  return true;
136 }
wchar_t qAxModuleFilename[MAX_PATH]
Definition: qaxserver.cpp:67
QString qAxInit()
Definition: qaxserver.cpp:111
bool qAxIsServer
Definition: qaxserver.cpp:64
void qAxCleanup()
Definition: qaxserver.cpp:139
HANDLE qAxInstance
Definition: qaxserver.cpp:65

◆ DllRegisterServer()

STDAPI DllRegisterServer ( )

Definition at line 66 of file qaxserverdll.cpp.

67 {
68  return UpdateRegistry(true);
69 }
HRESULT UpdateRegistry(int bRegister)

◆ DllUnregisterServer()

STDAPI DllUnregisterServer ( )

Definition at line 71 of file qaxserverdll.cpp.

72 {
73  return UpdateRegistry(false);
74 }
HRESULT UpdateRegistry(int bRegister)

◆ GetClassObject()

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

Referenced by DllGetClassObject().

◆ qAxCleanup()

void qAxCleanup ( )

Definition at line 139 of file qaxserver.cpp.

Referenced by DllMain().

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 DllMain().

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()

unsigned long qAxLockCount ( )

Definition at line 180 of file qaxserver.cpp.

Referenced by DllCanUnloadNow().

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

◆ UpdateRegistry()

HRESULT UpdateRegistry ( int  bRegister)

Variable Documentation

◆ qax_hhook

HHOOK qax_hhook = 0

◆ qax_ownQApp

bool qax_ownQApp = false

◆ qAxInstance

HANDLE qAxInstance

Definition at line 65 of file qaxserver.cpp.

Referenced by DllMain().

◆ qAxIsServer

bool qAxIsServer

Definition at line 64 of file qaxserver.cpp.

Referenced by DllMain().

◆ qAxModuleFilename

wchar_t qAxModuleFilename[MAX_PATH]

Definition at line 67 of file qaxserver.cpp.

Referenced by DllMain().

◆ qAxThreadId

uint qAxThreadId = 0
static

Definition at line 61 of file qaxserverdll.cpp.

Referenced by DllCanUnloadNow(), and DllGetClassObject().

◆ qAxTypeLibrary

ITypeLib* qAxTypeLibrary

Definition at line 66 of file qaxserver.cpp.

Referenced by qAxCleanup(), qAxInit(), QVariantToVARIANT(), and UpdateRegistry().