From 83bc5eb0e112fe0bf2d81aa0f4c50938015354f5 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Fri, 13 Sep 2013 12:32:49 +0300 Subject: [PATCH] WinRT: QLibrary & plugin support Avoid unsupported Win32 API while providing alternative codepaths for in-package library loading. Change-Id: Iaad059d6c94d0347cbaa8d9b9240806afcb29561 Done-with: Andrew Knight Done-with: Kamil Trzcinski Reviewed-by: Andrew Knight Reviewed-by: Oliver Wolff Reviewed-by: Lars Knoll --- src/corelib/plugin/qlibrary_win.cpp | 14 +++++++++++++- src/corelib/plugin/qsystemlibrary.cpp | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/corelib/plugin/qlibrary_win.cpp b/src/corelib/plugin/qlibrary_win.cpp index 16445f1163..928f2c5eb1 100644 --- a/src/corelib/plugin/qlibrary_win.cpp +++ b/src/corelib/plugin/qlibrary_win.cpp @@ -67,9 +67,10 @@ QStringList QLibraryPrivate::prefixes_sys() bool QLibraryPrivate::load_sys() { +#ifndef Q_OS_WINRT //avoid 'Bad Image' message box UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX); - +#endif // We make the following attempts at locating the library: // // WinCE @@ -108,7 +109,14 @@ bool QLibraryPrivate::load_sys() } Q_FOREACH (const QString &attempt, attempts) { +#ifndef Q_OS_WINRT pHnd = LoadLibrary((wchar_t*)QDir::toNativeSeparators(attempt).utf16()); +#else // Q_OS_WINRT + QString path = QDir::toNativeSeparators(QDir::current().relativeFilePath(fileName)); + pHnd = LoadPackagedLibrary((LPCWSTR)path.utf16(), 0); + if (pHnd) + qualifiedFileName = attempt; +#endif // !Q_OS_WINRT // If we have a handle or the last error is something other than "unable // to find the module", then bail out @@ -116,13 +124,16 @@ bool QLibraryPrivate::load_sys() break; } +#ifndef Q_OS_WINRT SetErrorMode(oldmode); +#endif if (!pHnd) { errorString = QLibrary::tr("Cannot load library %1: %2").arg(fileName).arg(qt_error_string()); } else { // Query the actual name of the library that was loaded errorString.clear(); +#ifndef Q_OS_WINRT wchar_t buffer[MAX_PATH]; ::GetModuleFileName(pHnd, buffer, MAX_PATH); @@ -133,6 +144,7 @@ bool QLibraryPrivate::load_sys() qualifiedFileName = moduleFileName; else qualifiedFileName = dir.filePath(moduleFileName); +#endif // !Q_OS_WINRT } return (pHnd != 0); } diff --git a/src/corelib/plugin/qsystemlibrary.cpp b/src/corelib/plugin/qsystemlibrary.cpp index e54efab0b8..bcd895dd4b 100644 --- a/src/corelib/plugin/qsystemlibrary.cpp +++ b/src/corelib/plugin/qsystemlibrary.cpp @@ -86,6 +86,12 @@ HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirect { return ::LoadLibrary(libraryName); } +#elif defined(Q_OS_WINRT) +HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */) +{ + Q_UNUSED(onlySystemDirectory); + return ::LoadPackagedLibrary(libraryName, 0); +} #else #if !defined(QT_BOOTSTRAPPED)