From 74251fb0fc57b1e0f7db0b561e4aa4c0347f6f37 Mon Sep 17 00:00:00 2001
From: Konstantin Ritt <ritt.ks@gmail.com>
Date: Fri, 7 Oct 2011 14:45:33 +0200
Subject: simplify the code by using QSystemLibrary a bit smarter

Merge-request: 2655
Reviewed-by: Jan-Arve Saether <jan-arve.saether@nokia.com>
---
 src/corelib/kernel/qeventdispatcher_win.cpp | 12 +++++----
 src/gui/kernel/qapplication_win.cpp         | 41 +++++++++--------------------
 src/network/kernel/qhostinfo_win.cpp        | 13 ++++-----
 3 files changed, 26 insertions(+), 40 deletions(-)

diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp
index 84663fa..3e367b7 100644
--- a/src/corelib/kernel/qeventdispatcher_win.cpp
+++ b/src/corelib/kernel/qeventdispatcher_win.cpp
@@ -328,13 +328,15 @@ static void resolveTimerAPI()
             return;
 #endif
         triedResolve = true;
-#if !defined(Q_OS_WINCE)
-        qtimeSetEvent = (ptimeSetEvent)QSystemLibrary::resolve(QLatin1String("winmm"), "timeSetEvent");
-        qtimeKillEvent = (ptimeKillEvent)QSystemLibrary::resolve(QLatin1String("winmm"), "timeKillEvent");
+#ifndef Q_OS_WINCE
+        QSystemLibrary library(QLatin1String("Mmtimer"));
 #else
-        qtimeSetEvent = (ptimeSetEvent)QSystemLibrary::resolve(QLatin1String("Mmtimer"), "timeSetEvent");
-        qtimeKillEvent = (ptimeKillEvent)QSystemLibrary::resolve(QLatin1String("Mmtimer"), "timeKillEvent");
+        QSystemLibrary library(QLatin1String("winmm"));
 #endif
+        if (library.load()) {
+            qtimeSetEvent = (ptimeSetEvent)library.resolve("timeSetEvent");
+            qtimeKillEvent = (ptimeKillEvent)library.resolve("timeKillEvent");
+        }
     }
 }
 
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index 756cb56..bca3acc 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -854,19 +854,15 @@ void qt_init(QApplicationPrivate *priv, int)
     qt_win_initialize_directdraw();
 
 #ifndef Q_OS_WINCE
-    ptrUpdateLayeredWindowIndirect =
-        (PtrUpdateLayeredWindowIndirect) QSystemLibrary::resolve(QLatin1String("user32"),
-                                                           "UpdateLayeredWindowIndirect");
-    ptrUpdateLayeredWindow =
-        (PtrUpdateLayeredWindow) QSystemLibrary::resolve(QLatin1String("user32"),
-                                                   "UpdateLayeredWindow");
+    QSystemLibrary user32(QLatin1String("user32"));
+    ptrUpdateLayeredWindowIndirect = (PtrUpdateLayeredWindowIndirect)user32.resolve("UpdateLayeredWindowIndirect");
+    ptrUpdateLayeredWindow = (PtrUpdateLayeredWindow)user32.resolve("UpdateLayeredWindow");
 
     if (ptrUpdateLayeredWindow && !ptrUpdateLayeredWindowIndirect)
         ptrUpdateLayeredWindowIndirect = qt_updateLayeredWindowIndirect;
 
     // Notify Vista and Windows 7 that we support highter DPI settings
-    ptrSetProcessDPIAware = (PtrSetProcessDPIAware)
-        QSystemLibrary::resolve(QLatin1String("user32"), "SetProcessDPIAware");
+    ptrSetProcessDPIAware = (PtrSetProcessDPIAware)user32.resolve("SetProcessDPIAware");
     if (ptrSetProcessDPIAware)
         ptrSetProcessDPIAware();
 #endif
@@ -886,29 +882,16 @@ void qt_init(QApplicationPrivate *priv, int)
     priv->GetGestureExtraArgs = (PtrGetGestureExtraArgs) &TKGetGestureExtraArguments;
 #elif !defined(Q_WS_WINCE)
   #if !defined(QT_NO_NATIVE_GESTURES)
-    priv->GetGestureInfo =
-            (PtrGetGestureInfo)QSystemLibrary::resolve(QLatin1String("user32"),
-                                                 "GetGestureInfo");
-    priv->GetGestureExtraArgs =
-            (PtrGetGestureExtraArgs)QSystemLibrary::resolve(QLatin1String("user32"),
-                                                      "GetGestureExtraArgs");
-    priv->CloseGestureInfoHandle =
-            (PtrCloseGestureInfoHandle)QSystemLibrary::resolve(QLatin1String("user32"),
-                                                         "CloseGestureInfoHandle");
-    priv->SetGestureConfig =
-            (PtrSetGestureConfig)QSystemLibrary::resolve(QLatin1String("user32"),
-                                                   "SetGestureConfig");
-    priv->GetGestureConfig =
-            (PtrGetGestureConfig)QSystemLibrary::resolve(QLatin1String("user32"),
-                                                   "GetGestureConfig");
+    priv->GetGestureInfo = (PtrGetGestureInfo)user32.resolve("GetGestureInfo");
+    priv->GetGestureExtraArgs = (PtrGetGestureExtraArgs)user32.resolve("GetGestureExtraArgs");
+    priv->CloseGestureInfoHandle = (PtrCloseGestureInfoHandle)user32.resolve("CloseGestureInfoHandle");
+    priv->SetGestureConfig = (PtrSetGestureConfig)user32.resolve("SetGestureConfig");
+    priv->GetGestureConfig = (PtrGetGestureConfig)user32.resolve("GetGestureConfig");
   #endif // QT_NO_NATIVE_GESTURES
     QSystemLibrary libTheme(QLatin1String("uxtheme"));
-    priv->BeginPanningFeedback =
-            (PtrBeginPanningFeedback)libTheme.resolve("BeginPanningFeedback");
-    priv->UpdatePanningFeedback =
-            (PtrUpdatePanningFeedback)libTheme.resolve("UpdatePanningFeedback");
-    priv->EndPanningFeedback =
-        (PtrEndPanningFeedback)libTheme.resolve("EndPanningFeedback");
+    priv->BeginPanningFeedback = (PtrBeginPanningFeedback)libTheme.resolve("BeginPanningFeedback");
+    priv->UpdatePanningFeedback = (PtrUpdatePanningFeedback)libTheme.resolve("UpdatePanningFeedback");
+    priv->EndPanningFeedback = (PtrEndPanningFeedback)libTheme.resolve("EndPanningFeedback");
 #endif
 #endif // QT_NO_GESTURES
 }
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index 6fc5b7b..03e72c4 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -85,14 +85,15 @@ static void resolveLibrary()
     // Attempt to resolve getaddrinfo(); without it we'll have to fall
     // back to gethostbyname(), which has no IPv6 support.
 #if !defined(Q_OS_WINCE)
-    local_getaddrinfo = (getaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "getaddrinfo");
-    local_freeaddrinfo = (freeaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "freeaddrinfo");
-    local_getnameinfo = (getnameinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "getnameinfo");
+    QSystemLibrary ws2lib(QLatin1String("ws2_32"));
 #else
-    local_getaddrinfo = (getaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "getaddrinfo");
-    local_freeaddrinfo = (freeaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "freeaddrinfo");
-    local_getnameinfo = (getnameinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "getnameinfo");
+    QSystemLibrary ws2lib(QLatin1String("ws2"));
 #endif
+    if (ws2lib.load()) {
+        local_getaddrinfo = (getaddrinfoProto)ws2lib.resolve("getaddrinfo");
+        local_freeaddrinfo = (freeaddrinfoProto)ws2lib.resolve("freeaddrinfo");
+        local_getnameinfo = (getnameinfoProto)ws2lib.resolve("getnameinfo");
+    }
 }
 
 #if defined(Q_OS_WINCE)
-- 
cgit v0.12