embedserv/source/inprocserv/dllentry.cxx          |   77 +++++-----------------
 shell/source/win32/shlxthandler/util/registry.cxx |    4 -
 vcl/win/window/salframe.cxx                       |    4 -
 3 files changed, 22 insertions(+), 63 deletions(-)

New commits:
commit 750d56bc867b0f58228c5d5b663ba0e9a2424f82
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Jun 15 23:35:45 2024 +0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Jun 17 14:15:24 2024 +0200

    Remove some unneeded casts
    
    This also changes the API used in WriteLibraryToRegistry.
    
    Change-Id: Iba4c20567275a64684be8695c771e4c5535956ab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168912
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168992

diff --git a/embedserv/source/inprocserv/dllentry.cxx 
b/embedserv/source/inprocserv/dllentry.cxx
index 4cc8ebdc6024..4b430336d7e5 100644
--- a/embedserv/source/inprocserv/dllentry.cxx
+++ b/embedserv/source/inprocserv/dllentry.cxx
@@ -71,7 +71,7 @@ namespace {
                     pos += suffix.copy(pos, suffix.size());
                     assert(pos == end - 1);
                     *pos = 0;
-                    if (ERROR_SUCCESS == RegSetValueExW(HKEY_LOCAL_MACHINE, 
pSubKey, 0, REG_SZ, reinterpret_cast<const BYTE*>(pLibrary), 
nLen*sizeof(wchar_t)))
+                    if (ERROR_SUCCESS == RegSetKeyValueW(HKEY_LOCAL_MACHINE, 
pSubKey, nullptr, REG_SZ, pLibrary, nLen*sizeof(wchar_t)))
                         bLocalSuccess = true;
                 }
 
diff --git a/shell/source/win32/shlxthandler/util/registry.cxx 
b/shell/source/win32/shlxthandler/util/registry.cxx
index 5e4f73797606..209eb399c923 100644
--- a/shell/source/win32/shlxthandler/util/registry.cxx
+++ b/shell/source/win32/shlxthandler/util/registry.cxx
@@ -30,7 +30,7 @@
 
 bool SetRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, const 
Filepath_char_t* ValueName, const Filepath_char_t* Value)
 {
-    int rc = RegSetKeyValueW(RootKey, KeyName, ValueName, REG_SZ, 
reinterpret_cast<LPCVOID>(Value),
+    int rc = RegSetKeyValueW(RootKey, KeyName, ValueName, REG_SZ, Value,
                              (wcslen(Value) + 1) * sizeof(*Value));
     return (ERROR_SUCCESS == rc);
 }
@@ -59,7 +59,7 @@ bool QueryRegistryKey(HKEY RootKey, const Filepath_char_t* 
KeyName, const Filepa
 {
     DWORD dwBytes = dwBufLen * sizeof(*pszData);
     LSTATUS rc = RegGetValueW(RootKey, KeyName, ValueName, RRF_RT_REG_SZ, 
nullptr,
-                              reinterpret_cast<LPBYTE>(pszData), &dwBytes);
+                              pszData, &dwBytes);
     return (ERROR_SUCCESS == rc);
 }
 
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index ebcb85f55cff..1661d3408fa8 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -2656,7 +2656,7 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings )
         wchar_t aValueBuf[10];
         DWORD   nValueSize = sizeof( aValueBuf );
         if (RegGetValueW(HKEY_CURRENT_USER, L"Control Panel\Desktop", 
L"MenuShowDelay",
-                         RRF_RT_REG_SZ, nullptr, 
reinterpret_cast<LPVOID>(aValueBuf), &nValueSize)
+                         RRF_RT_REG_SZ, nullptr, aValueBuf, &nValueSize)
             == ERROR_SUCCESS)
         {
             aMouseSettings.SetMenuDelay( static_cast<sal_uLong>(ImplW2I( 
aValueBuf )) );
@@ -2947,7 +2947,7 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings )
         DWORD   nValueSize = sizeof( aValueBuf );
         if (RegGetValueW(HKEY_CURRENT_USER,
                          L"Control 
Panel\International\Calendars\TwoDigitYearMax", L"1",
-                         RRF_RT_REG_SZ, nullptr, 
reinterpret_cast<LPVOID>(aValueBuf), &nValueSize)
+                         RRF_RT_REG_SZ, nullptr, aValueBuf, &nValueSize)
             == ERROR_SUCCESS)
         {
             DWORD nValue = static_cast<sal_uLong>(ImplW2I(aValueBuf));
commit 1e27983ce1c1433c6bdc1be9550a307a5bf357a5
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Jun 15 15:15:42 2024 +0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Jun 17 14:15:16 2024 +0200

    tdf#161585: fix DllRegisterServer implementation
    
    The buffer was prepared with a wrong length (one too few spaces); thus,
    the resulting registry key path was wrong, and opening it failed.
    
    While at it, use a normal WinAPI to stringify GUIDs, and simplify code.
    
    Change-Id: I9a51a5aa70791106055c615fd15a32e5e07847a9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168903
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 7b2c82ff14094aad4cb64a9d2531fd8fe48229b1)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168938
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/embedserv/source/inprocserv/dllentry.cxx 
b/embedserv/source/inprocserv/dllentry.cxx
index 12dee7b0cc85..4cc8ebdc6024 100644
--- a/embedserv/source/inprocserv/dllentry.cxx
+++ b/embedserv/source/inprocserv/dllentry.cxx
@@ -19,7 +19,9 @@
 
 #include <sal/types.h>
 
+#include <cassert>
 #include <stdio.h>
+#include <string_view>
 #include "inprocembobj.h"
 #include <embservconst.h>
 
@@ -44,76 +46,33 @@ static ULONG g_nLock = 0;
 
 
 namespace {
-    void FillCharFromInt( int nValue, wchar_t* pBuf, int nLen )
-    {
-        int nInd = 0;
-        while( nInd < nLen )
-        {
-            char nSign = ( nValue / ( 1 << ( ( nLen - nInd - 1 ) * 4 ) ) ) % 
16;
-            if ( nSign >= 0 && nSign <= 9 )
-                pBuf[nInd] = nSign + L'0';
-            else if (nSign >= 10)
-                pBuf[nInd] = nSign - 10 + L'a';
-
-            nInd++;
-        }
-    }
-
-    int GetStringFromClassID( const GUID& guid, wchar_t* pBuf, int nLen )
-    {
-        // is not allowed to insert
-        if ( nLen < 38 )
-            return 0;
-
-        pBuf[0] = L'{';
-        FillCharFromInt( guid.Data1, &pBuf[1], 8 );
-        pBuf[9] = L'-';
-        FillCharFromInt( guid.Data2, &pBuf[10], 4 );
-        pBuf[14] = L'-';
-        FillCharFromInt( guid.Data3, &pBuf[15], 4 );
-        pBuf[19] = L'-';
-
-        int nInd = 0;
-        for ( nInd = 0; nInd < 2 ; nInd++ )
-            FillCharFromInt( guid.Data4[nInd], &pBuf[20 + 2*nInd], 2 );
-        pBuf[24] = L'-';
-        for ( nInd = 2; nInd < 8 ; nInd++ )
-            FillCharFromInt( guid.Data4[nInd], &pBuf[20 + 1 + 2*nInd], 2 );
-        pBuf[37] = L'}';
-
-        return 38;
-    }
-
     HRESULT WriteLibraryToRegistry( const wchar_t* pLibrary, DWORD nLen )
     {
         HRESULT hRes = E_FAIL;
         if ( pLibrary && nLen )
         {
-            HKEY hKey = nullptr;
-
             hRes = S_OK;
             for ( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
             {
-                const wchar_t pSubKeyTemplate[] = 
L"Software\Classes\CLSID\.....................................\InprocHandler32";
-                wchar_t pSubKey[std::size(pSubKeyTemplate)];
-                wcsncpy(pSubKey, pSubKeyTemplate, std::size(pSubKeyTemplate));
-
-                int nGuidLen = GetStringFromClassID( *guidList[nInd], 
&pSubKey[23], 38 );
+                constexpr std::wstring_view prefix(L"Software\Classes\CLSID\");
+                constexpr std::wstring_view suffix(L"\InprocHandler32");
+                constexpr size_t guidStringSize
+                    = std::size(L"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}");
+                constexpr size_t bufsize = prefix.size() + guidStringSize + 
suffix.size();
+                wchar_t pSubKey[bufsize];
+                wchar_t *pos = pSubKey, *end = pSubKey + std::size(pSubKey);
+                pos += prefix.copy(pos, prefix.size());
+                int nGuidLen = StringFromGUID2(*guidList[nInd], pos, end - 
pos);
 
                 bool bLocalSuccess = false;
-                if ( nGuidLen == 38 )
+                if (nGuidLen == guidStringSize)
                 {
-                    if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, 
pSubKey, &hKey ) )
-                    {
-                        if ( ERROR_SUCCESS == RegSetValueExW( hKey, L"", 0, 
REG_SZ, reinterpret_cast<const BYTE*>(pLibrary), nLen*sizeof(wchar_t) ) )
-                            bLocalSuccess = true;
-                    }
-
-                    if ( hKey )
-                    {
-                        RegCloseKey( hKey );
-                        hKey = nullptr;
-                    }
+                    pos += nGuidLen - 1;
+                    pos += suffix.copy(pos, suffix.size());
+                    assert(pos == end - 1);
+                    *pos = 0;
+                    if (ERROR_SUCCESS == RegSetValueExW(HKEY_LOCAL_MACHINE, 
pSubKey, 0, REG_SZ, reinterpret_cast<const BYTE*>(pLibrary), 
nLen*sizeof(wchar_t)))
+                        bLocalSuccess = true;
                 }
 
                 if ( !bLocalSuccess )

Reply via email to