[Libreoffice-commits] core.git: embedserv/source sfx2/source vcl/win

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 28 16:09:32 UTC 2021


 embedserv/source/embed/tracker.cxx   |   12 +++++++++++-
 sfx2/source/appl/shutdowniconw32.cxx |    9 ++++++++-
 vcl/win/dtrans/MtaOleClipb.cxx       |   23 ++++++++++++++++-------
 vcl/win/dtrans/target.cxx            |   10 +++++++++-
 4 files changed, 44 insertions(+), 10 deletions(-)

New commits:
commit d249bd5a3dfe13052ce9aa91bad94ec7d60604d4
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Thu Jan 28 08:43:12 2021 +0100
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Thu Jan 28 17:08:47 2021 +0100

    WIN handle GetMessageW return values
    
    GetMessageW returns a BOOL with three defined return values; a
    bit unexpected (-1 = error, 0 = WM_QUIT, * = dispatch message).
    So this tries to handle the non-dispatch results in some way.
    
    It's not clear for me, if there is some sensible way to "recover"
    from an error, but from all I've read it doesn't look like it.
    "Recover" means in this case, that the last call failed but next
    call may still succeed without changing the parameters.
    
    Change-Id: Ib1f366c7ce8b48158d1935938b49d8da991b30e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110043
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/embedserv/source/embed/tracker.cxx b/embedserv/source/embed/tracker.cxx
index 00260481c0a8..dbe114660f61 100644
--- a/embedserv/source/embed/tracker.cxx
+++ b/embedserv/source/embed/tracker.cxx
@@ -22,11 +22,18 @@
 #include <algorithm>
 
 #include <sal/types.h>
+#include <sal/log.hxx>
 
 #include <stdafx.h>
 #include <stddef.h>
 #include <syswinwrapper.hxx>
 
+// windowserrorstring.hxx includes postwin.h, which #undef OPAQUE, so "#redef" it
+#include <comphelper/windowserrorstring.hxx>
+#ifdef OPAQUE
+#error OPAQUE should not be defined!?
+#endif
+#define OPAQUE 2
 
 static HCURSOR afxCursors[10] = { nullptr, };
 static HBRUSH afxHalftoneBrush = nullptr;
@@ -398,7 +405,10 @@ BOOL Tracker::TrackHandle(int nHandle,HWND hWnd,POINT point,HWND hWndClipTo)
     for (;;)
     {
         MSG msg;
-        GetMessageW(&msg, nullptr, 0, 0);
+        BOOL bRet = GetMessageW(&msg, nullptr, 0, 0);
+        SAL_WARN_IF(-1 == bRet, "embedserv", "GetMessageW failed: " << WindowsErrorString(GetLastError()));
+        if (-1 == bRet || 0 == bRet)
+            break;
 
         if (GetCapture() != hWnd)
             break;
diff --git a/sfx2/source/appl/shutdowniconw32.cxx b/sfx2/source/appl/shutdowniconw32.cxx
index 0f1aa36301d7..298d84bf7d89 100644
--- a/sfx2/source/appl/shutdowniconw32.cxx
+++ b/sfx2/source/appl/shutdowniconw32.cxx
@@ -33,6 +33,7 @@
 #include <osl/thread.h>
 #include <systools/win32/qswin32.h>
 #include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/windowserrorstring.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
 
 #include <set>
@@ -458,9 +459,15 @@ static DWORD WINAPI SystrayThread( LPVOID /*lpParam*/ )
         );
 
     MSG msg;
+    BOOL bRet;
 
-    while ( GetMessageW( &msg, nullptr, 0, 0 ) )
+    while ((bRet = GetMessageW(&msg, nullptr, 0, 0)) != 0)
     {
+        if (-1 == bRet)
+        {
+            SAL_WARN("sfx.appl", "GetMessageW failed: " << WindowsErrorString(GetLastError()));
+            return 1;
+        }
         TranslateMessage( &msg );
         DispatchMessageW( &msg );
     }
diff --git a/vcl/win/dtrans/MtaOleClipb.cxx b/vcl/win/dtrans/MtaOleClipb.cxx
index 6fc789e27d9d..f6e471925516 100644
--- a/vcl/win/dtrans/MtaOleClipb.cxx
+++ b/vcl/win/dtrans/MtaOleClipb.cxx
@@ -45,6 +45,8 @@
 
 #include <systools/win32/comtools.hxx>
 
+#include <comphelper/windowserrorstring.hxx>
+
 //  namespace directives
 
 using osl::MutexGuard;
@@ -642,22 +644,29 @@ unsigned int CMtaOleClipboard::run( )
 
     createMtaOleReqWnd( );
 
-    unsigned int nRet;
+    unsigned int nRet = ~0U; // = error
 
     if ( IsWindow( m_hwndMtaOleReqWnd ) )
     {
         if ( nullptr != m_hEvtThrdReady )
             SetEvent( m_hEvtThrdReady );
 
+        nRet = 0;
+
         // pumping messages
         MSG msg;
-        while( GetMessageW( &msg, nullptr, 0, 0 ) )
-            DispatchMessageW( &msg );
-
-        nRet = 0;
+        BOOL bRet;
+        while ((bRet = GetMessageW(&msg, nullptr, 0, 0)) != 0)
+        {
+            if (-1 == bRet)
+            {
+                SAL_WARN("vcl.win.dtrans", "GetMessageW failed: " << WindowsErrorString(GetLastError()));
+                nRet = ~0U;
+                break;
+            }
+            DispatchMessageW(&msg);
+        }
     }
-    else
-        nRet = ~0U;
 
     OleUninitialize( );
 
diff --git a/vcl/win/dtrans/target.cxx b/vcl/win/dtrans/target.cxx
index adddabab7038..45a8515bd414 100644
--- a/vcl/win/dtrans/target.cxx
+++ b/vcl/win/dtrans/target.cxx
@@ -30,6 +30,8 @@
 #include "targetdragcontext.hxx"
 #include <rtl/ustring.h>
 #include <osl/thread.h>
+#include <sal/log.hxx>
+#include <comphelper/windowserrorstring.hxx>
 
 #include "DOTransferable.hxx"
 
@@ -206,8 +208,14 @@ DWORD WINAPI DndTargetOleSTAFunc(LPVOID pParams)
         DWORD threadId= GetCurrentThreadId();
         // We force the creation of a thread message queue. This is necessary
         // for a later call to AttachThreadInput
-        while( GetMessageW(&msg, nullptr, 0, 0) )
+        BOOL bRet;
+        while ((bRet = GetMessageW(&msg, nullptr, 0, 0)) != 0)
         {
+            if (-1 == bRet)
+            {
+                SAL_WARN("vcl.win.dtrans", "GetMessageW failed: " << WindowsErrorString(GetLastError()));
+                break;
+            }
             if( msg.message == WM_REGISTERDRAGDROP)
             {
                 DropTarget *pTarget= reinterpret_cast<DropTarget*>(msg.wParam);


More information about the Libreoffice-commits mailing list