Qt 4.8
qsystemlibrary.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsystemlibrary_p.h"
43 
44 #include <QtCore/qvarlengtharray.h>
45 #include <QtCore/qstringlist.h>
46 #include <QtCore/qfileinfo.h>
47 
83 
84 #if defined(Q_OS_WINCE)
85 HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
86 {
87  Q_UNUSED(onlySystemDirectory);
88  return ::LoadLibrary(libraryName);
89 }
90 #else
91 
92 #if !defined(QT_BOOTSTRAPPED)
93 extern QString qAppFileName();
94 #endif
95 
96 static inline QString qSystemDirectory()
97 {
99 
100  UINT retLen = ::GetSystemDirectory(fullPath.data(), MAX_PATH);
101  if (retLen > MAX_PATH) {
102  fullPath.resize(retLen);
103  retLen = ::GetSystemDirectory(fullPath.data(), retLen);
104  }
105  // in some rare cases retLen might be 0
106  return QString::fromWCharArray(fullPath.constData(), int(retLen));
107 }
108 
109 HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
110 {
111  QStringList searchOrder;
112 
113 #if !defined(QT_BOOTSTRAPPED)
114  if (!onlySystemDirectory)
115  searchOrder << QFileInfo(qAppFileName()).path();
116 #endif
117  searchOrder << qSystemDirectory();
118 
119  if (!onlySystemDirectory) {
120  const QString PATH = QString::fromWCharArray((const wchar_t *)_wgetenv(L"PATH"));
121  searchOrder << PATH.split(QLatin1Char(';'), QString::SkipEmptyParts);
122  }
123 
124  const QString fileName = QString::fromWCharArray(libraryName) + QLatin1String(".dll");
125  // Start looking in the order specified
126  for (int i = 0; i < searchOrder.count(); ++i) {
127  QString fullPathAttempt = searchOrder.at(i);
128  if (!fullPathAttempt.endsWith(QLatin1Char('\\')))
129  fullPathAttempt.append(QLatin1Char('\\'));
130  fullPathAttempt.append(fileName);
131  HINSTANCE inst = ::LoadLibrary((const wchar_t *)fullPathAttempt.utf16());
132  if (inst != 0)
133  return inst;
134  }
135 
136  return 0;
137 }
138 
139 #endif // !Q_OS_WINCE
140 
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 resize(int size)
const T * constData() const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString qAppFileName()
bool load(bool onlySystemDirectory=true)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
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
QString & append(QChar c)
Definition: qstring.cpp:1777
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
QString path() const
Returns the file&#39;s path.
Definition: qfileinfo.cpp:615
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
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
#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
static QString fileName(const QString &fileUrl)
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