OSDN Git Service

Some code refactoring in UpdateChecker class.
[mutilities/MUtilities.git] / src / Utils_Win32.cpp
index 0be05b3..2ec4ae5 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // MuldeR's Utilities for Qt
-// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@
 #ifndef _INC_WINDOWS
 #define WIN32_LEAN_AND_MEAN 1
 #include <Windows.h>
+#include <ObjIdl.h>  // required by QWinMime in QtWinExtras
 #endif //_INC_WINDOWS
 
 //Qt
 #include <QReadWriteLock>
 #include <QLibrary>
 #include <QHash>
+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
+#include <QtWinExtras>
+#endif
+
+//Qt5 support
+#if QT_VERSION > QT_VERSION_CHECK(5,0,0)
+#define PIXMAP2HICON(X) QtWin::toHICON((X))
+#else
+#define PIXMAP2HICON(X) (X).toWinHICON()
+#endif
 
 ///////////////////////////////////////////////////////////////////////////////
 // QICON TO HICON
 ///////////////////////////////////////////////////////////////////////////////
 
-uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon &icon, const int w, const int h)
+uintptr_t MUtils::Win32Utils::qicon_to_hicon(const QIcon *const icon, const int w, const int h)
 {
-       if(!icon.isNull())
+       if(!icon->isNull())
        {
-               QPixmap pixmap = icon.pixmap(w, h);
+               QPixmap pixmap = icon->pixmap(w, h);
                if(!pixmap.isNull())
                {
-                       return (uintptr_t) pixmap.toWinHICON();
+                       return (uintptr_t) PIXMAP2HICON(pixmap);
                }
        }
        return NULL;
@@ -61,7 +72,7 @@ typedef QPair<QSharedPointer<QLibrary>, FunctionMap> LibraryItem;
 static QReadWriteLock              g_resolve_lock;
 static QHash<QString, LibraryItem> g_resolve_libs;
 
-uintptr_t MUtils::Win32Utils::resolve_helper(const QString &libraryName, const QString &functionName)
+const uintptr_t &MUtils::Win32Utils::resolve_helper(const QString &libraryName, const QString &functionName)
 {
        const QString libraryNameFolded = libraryName.toCaseFolded().trimmed();
        const QString functionIdTrimmed = functionName.trimmed();
@@ -97,7 +108,8 @@ uintptr_t MUtils::Win32Utils::resolve_helper(const QString &libraryName, const Q
        LibraryItem &lib = g_resolve_libs[libraryNameFolded];
        if (lib.first.isNull() || (!lib.first->isLoaded()))
        {
-               return NULL; /*library unavailable*/
+               static const uintptr_t null = NULL;
+               return null; /*library unavailable*/
        }
 
        //Lookup the function