Qt 4.8
Public Functions | Static Public Functions | Properties | List of all members
QSystemLibrary Class Reference

#include <qsystemlibrary_p.h>

Public Functions

bool isLoaded ()
 
bool load (bool onlySystemDirectory=true)
 
 QSystemLibrary (const QString &libraryName)
 
 QSystemLibrary (const wchar_t *libraryName)
 
void * resolve (const char *symbol)
 

Static Public Functions

static Q_CORE_EXPORT HINSTANCE load (const wchar_t *lpFileName, bool onlySystemDirectory=true)
 
static void * resolve (const QString &libraryName, const char *symbol)
 

Properties

bool m_didLoad
 
HINSTANCE m_handle
 
QString m_libraryName
 

Detailed Description

Warning
This function is not part of the public interface.

The purpose of this class is to load only libraries that are located in well-known and trusted locations on the filesystem. It does not suffer from the security problem that QLibrary has, therefore it will never search in the current directory.

The search order is the same as the order in DLL Safe search mode Windows, except that we don't search: The current directory The 16-bit system directory. (normally c:/windows/system) The Windows directory. (normally c:/windows)

This means that the effective search order is:

  1. Application path.
  2. System libraries path.
  3. Trying all paths inside the PATH environment variable.

Note, when onlySystemDirectory is true it will skip 1) and 3).

DLL Safe search mode is documented in the "Dynamic-Link Library Search Order" document on MSDN.

Since library loading code is sometimes shared between Windows and WinCE, this class can also be used on WinCE. However, its implementation just calls the LoadLibrary() function. This is ok since it is documented as not loading from the current directory on WinCE. This behaviour is documented in the documentation for LoadLibrary for Windows CE at MSDN. (http://msdn.microsoft.com/en-us/library/ms886736.aspx)

Definition at line 52 of file qsystemlibrary_p.h.

Constructors and Destructors

◆ QSystemLibrary() [1/2]

QSystemLibrary::QSystemLibrary ( const QString libraryName)
inlineexplicit

Definition at line 55 of file qsystemlibrary_p.h.

Referenced by resolve().

56  {
57  m_libraryName = libraryName;
58  m_handle = 0;
59  m_didLoad = false;
60  }

◆ QSystemLibrary() [2/2]

QSystemLibrary::QSystemLibrary ( const wchar_t *  libraryName)
inlineexplicit

Definition at line 62 of file qsystemlibrary_p.h.

63  {
65  m_handle = 0;
66  m_didLoad = false;
67  }
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

Functions

◆ isLoaded()

bool QSystemLibrary::isLoaded ( )
inline

Definition at line 76 of file qsystemlibrary_p.h.

Referenced by QDesktopWidgetPrivate::init().

77  {
78  return (m_handle != 0);
79  }

◆ load() [1/2]

bool QSystemLibrary::load ( bool  onlySystemDirectory = true)
inline

Definition at line 69 of file qsystemlibrary_p.h.

Referenced by QWindowsSystemProxy::init(), load(), loadIconFromShell32(), loadOpenSslWin32(), resolve(), resolveGdi32(), resolveLibrary(), resolveLibs(), resolveTimerAPI(), resolveUNCLibs(), and QSystemLocalePrivate::uiLanguages().

70  {
71  m_handle = load((const wchar_t *)m_libraryName.utf16(), onlySystemDirectory);
72  m_didLoad = true;
73  return (m_handle != 0);
74  }
bool load(bool onlySystemDirectory=true)
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ load() [2/2]

HINSTANCE QSystemLibrary::load ( const wchar_t *  lpFileName,
bool  onlySystemDirectory = true 
)
static

Definition at line 85 of file qsystemlibrary.cpp.

86 {
87  Q_UNUSED(onlySystemDirectory);
88  return ::LoadLibrary(libraryName);
89 }
#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

◆ resolve() [1/2]

void* QSystemLibrary::resolve ( const char *  symbol)
inline

Definition at line 81 of file qsystemlibrary_p.h.

Referenced by QSystemTrayIconSys::findIconGeometry(), QDesktopWidgetPrivate::init(), QWindowsSystemProxy::init(), init_wintab_functions(), initWinTabFunctions(), isProcessBeingDebugged(), launchWebBrowser(), QSystemTrayIconSys::QSystemTrayIconSys(), qt_grab_cursor(), qt_init(), qt_win_get_save_file_name(), qt_win_resolve_libs(), QtWndProc(), QVariantToVARIANT(), QWindowsStylePrivate::QWindowsStylePrivate(), registerFont(), resolveAygLibs(), resolveGdi32(), resolveLibrary(), resolveLibs(), QVistaHelper::resolveSymbols(), QWindowsVistaStylePrivate::resolveSymbols(), QWindowsXPStylePrivate::resolveSymbols(), resolveTimerAPI(), resolveUNCLibs(), shared_dc(), QETWidget::translateMouseEvent(), QSystemLocalePrivate::uiLanguages(), and windowsConfigPath().

82  {
83  if (!m_didLoad)
84  load();
85  if (!m_handle)
86  return 0;
87 #ifdef Q_OS_WINCE
88  return (void*)GetProcAddress(m_handle, (const wchar_t*)QString::fromLatin1(symbol).utf16());
89 #else
90  return (void*)GetProcAddress(m_handle, symbol);
91 #endif
92  }
bool load(bool onlySystemDirectory=true)
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

◆ resolve() [2/2]

static void* QSystemLibrary::resolve ( const QString libraryName,
const char *  symbol 
)
inlinestatic

Definition at line 94 of file qsystemlibrary_p.h.

95  {
96  return QSystemLibrary(libraryName).resolve(symbol);
97  }
QSystemLibrary(const QString &libraryName)

Properties

◆ m_didLoad

bool QSystemLibrary::m_didLoad
private

Definition at line 104 of file qsystemlibrary_p.h.

Referenced by load(), QSystemLibrary(), and resolve().

◆ m_handle

HINSTANCE QSystemLibrary::m_handle
private

Definition at line 102 of file qsystemlibrary_p.h.

Referenced by isLoaded(), load(), QSystemLibrary(), and resolve().

◆ m_libraryName

QString QSystemLibrary::m_libraryName
private

Definition at line 103 of file qsystemlibrary_p.h.

Referenced by load(), and QSystemLibrary().


The documentation for this class was generated from the following files: