From c874834280fccd39ee61a6d44babc5c7eb8ec773 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 9 Nov 2025 12:53:01 +0500 Subject: [PATCH] Simplify WinBITMAPToOOBMP a bit Use CreateCompatibleDC to avoid using actual desktop DC. Use ScopedHDC for reliable resource management. Change-Id: Ia6662cf50355e4259e1d985d1deec8a828f9c8ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193649 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- vcl/win/dtrans/FmtFilter.cxx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/vcl/win/dtrans/FmtFilter.cxx b/vcl/win/dtrans/FmtFilter.cxx index 47aff85c6cf4..d62389235994 100644 --- a/vcl/win/dtrans/FmtFilter.cxx +++ b/vcl/win/dtrans/FmtFilter.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -397,8 +398,6 @@ css::uno::Sequence CF_HDROPToFileList(HGLOBAL hGlobal) Sequence< sal_Int8 > WinBITMAPToOOBMP( HBITMAP aHBMP ) { - Sequence< sal_Int8 > ooBmpStream; - if (BITMAP bm{}; GetObjectW(aHBMP, sizeof(bm), &bm)) { size_t nDataBytes = ((bm.bmWidth * bm.bmBitsPixel + 31) / 32) * 4 * bm.bmHeight; @@ -414,15 +413,14 @@ Sequence< sal_Int8 > WinBITMAPToOOBMP( HBITMAP aHBMP ) pBmp->bmiHeader.biBitCount = bm.bmBitsPixel; pBmp->bmiHeader.biCompression = BI_RGB; - HDC hdc = GetDC(nullptr); - if (GetDIBits(hdc, aHBMP, 0, bm.bmHeight, pBmp + 1, pBmp, DIB_RGB_COLORS)) + ScopedHDC hdc(CreateCompatibleDC(nullptr)); + if (GetDIBits(hdc.get(), aHBMP, 0, bm.bmHeight, pBmp + 1, pBmp, DIB_RGB_COLORS)) { - ooBmpStream = WinDIBToOOBMP( aBitmapStream ); + return WinDIBToOOBMP(aBitmapStream); } - ReleaseDC(nullptr, hdc); } - return ooBmpStream; + return {}; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */