extensions/source/ole/servprov.cxx | 34 +--------- helpcompiler/source/HelpIndexer.cxx | 3 sal/osl/w32/file_dirvol.cxx | 5 + sal/osl/w32/file_url.cxx | 5 - sal/osl/w32/file_url.hxx | 2 sal/osl/w32/module.cxx | 3 sal/osl/w32/process.cxx | 7 +- sal/osl/w32/profile.cxx | 16 ++-- sal/osl/w32/tempfile.cxx | 5 + setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx | 3 shell/source/win32/SysShExec.cxx | 6 - sw/source/uibase/dochdl/swdtflvr.cxx | 7 +- vcl/win/app/fileregistration.cxx | 23 +++--- 13 files changed, 52 insertions(+), 67 deletions(-)
New commits: commit 2e31b49edea62b82163cb48444a20339f15f6aa8 Author: Mike Kaganski <[email protected]> AuthorDate: Sat Jan 18 19:04:00 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Jan 19 13:25:55 2025 +0100 Use CComPtr and its method to create instance by prog id Also CComVariant can be created directly from CComPtr, acquiring its reference as needed. Change-Id: I0dda0687eca5eefd8d3b7266f895d485f145eea4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180447 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/extensions/source/ole/servprov.cxx b/extensions/source/ole/servprov.cxx index 0c3920ccca11..a37703eb012d 100644 --- a/extensions/source/ole/servprov.cxx +++ b/extensions/source/ole/servprov.cxx @@ -395,47 +395,21 @@ css::uno::Sequence<OUString> OleClient::getSupportedServiceNames() Reference<XInterface> SAL_CALL OleClient::createInstance(const OUString& ServiceSpecifier) { Reference<XInterface> ret; - HRESULT result; - IUnknown* pUnknown = nullptr; - CLSID classId; o2u_attachCurrentThread(); - result = CLSIDFromProgID( - o3tl::toW(ServiceSpecifier.getStr()), //Pointer to the ProgID - &classId); //Pointer to the CLSID - - - if (result == NOERROR) - { - result = CoCreateInstance( - classId, //Class identifier (CLSID) of the object - nullptr, //Pointer to whether object is or isn't part of an aggregate - CLSCTX_SERVER, //Context for running executable code - IID_IUnknown, //Reference to the identifier of the interface - reinterpret_cast<void**>(&pUnknown)); //Address of output variable that receives - // the interface pointer requested in riid - } - - if (pUnknown != nullptr) + CComPtr<IUnknown> pUnknown; + pUnknown.CoCreateInstance(o3tl::toW(ServiceSpecifier.getStr()), nullptr, CLSCTX_SERVER); + if (pUnknown) { Any any; - CComVariant variant; - - V_VT(&variant) = VT_UNKNOWN; - V_UNKNOWN(&variant) = pUnknown; - // AddRef for Variant - pUnknown->AddRef(); - - // When the object is wrapped, then its refcount is increased + CComVariant variant(pUnknown); variantToAny(&variant, any); if (any.getValueTypeClass() == TypeClass_INTERFACE) { any >>= ret; } - pUnknown->Release(); // CoCreateInstance } - return ret; } commit afb8bce96f8283ece298d422422415b9599eef2f Author: Mike Kaganski <[email protected]> AuthorDate: Sat Jan 18 22:31:17 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Jan 19 13:25:42 2025 +0100 Use EXTENDED_MAX_PATH for consistency ... instead of literal 32767 or duplicating constants. Change-Id: I43d7bba2fa2dc74ae65b23f54fb7765f95084895 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180464 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/helpcompiler/source/HelpIndexer.cxx b/helpcompiler/source/HelpIndexer.cxx index 65e46743b482..738ea0d3e092 100644 --- a/helpcompiler/source/HelpIndexer.cxx +++ b/helpcompiler/source/HelpIndexer.cxx @@ -26,6 +26,7 @@ #include <o3tl/char16_t2wchar_t.hxx> #include <prewin.h> #include <postwin.h> +#include <systools/win32/extended_max_path.hxx> #endif using namespace lucene::document; @@ -64,7 +65,7 @@ auto TryWithUnicodePathWorkaround(const OUString& ustrPath, const Constructor& c // For a workaround, try short name, which should only contain ASCII characters. Would // not help (i.e., would return original long name) if short (8.3) file name creation is // disabled in OS or volume settings. - wchar_t buf[32767]; + wchar_t buf[EXTENDED_MAX_PATH]; if (GetShortPathNameW(o3tl::toW(ustrPath.getStr()), buf, std::size(buf)) == 0) throw; sPath = OUStringToOString(o3tl::toU(buf), eThreadEncoding); diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index 7599be112a8d..0064e170641a 100644 --- a/sal/osl/w32/file_dirvol.cxx +++ b/sal/osl/w32/file_dirvol.cxx @@ -17,6 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <systools/win32/extended_max_path.hxx> #include <systools/win32/uwinapi.h> #include "file_url.hxx" @@ -1539,7 +1542,7 @@ oslFileError SAL_CALL osl_getFileStatus( { if ( !pItemImpl->bFullPathNormalized ) { - ::osl::LongPathBuffer<sal_Unicode> aBuffer(MAX_LONG_PATH); + osl::LongPathBuffer<sal_Unicode> aBuffer(EXTENDED_MAX_PATH); sal_uInt32 nNewLen = GetLongPathNameW(o3tl::toW(sFullPath.getStr()), o3tl::toW(aBuffer), aBuffer.getBufSizeInSymbols()); diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx index 82428a326621..ea90ccad7f2b 100644 --- a/sal/osl/w32/file_url.cxx +++ b/sal/osl/w32/file_url.cxx @@ -25,6 +25,7 @@ #include <stack> #include <string_view> +#include <systools/win32/extended_max_path.hxx> #include <systools/win32/uwinapi.h> #include "file_url.hxx" @@ -594,7 +595,7 @@ static OUString GetCaseCorrectPathName(std::u16string_view sysPath) wchar_t* const pStart = pEnd; pEnd = std::copy(sysPath.begin() + sysPathOffset, sysPath.end(), pStart); *pEnd = 0; - osl::LongPathBuffer<wchar_t> aBuf(MAX_LONG_PATH); + osl::LongPathBuffer<wchar_t> aBuf(EXTENDED_MAX_PATH); while (pEnd > pStart) { std::u16string_view curPath(o3tl::toU(pPath), pEnd - pPath); @@ -944,7 +945,7 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr { // Call GetFullPathNameW to get current directory on ustrRelSysPath's drive wchar_t baseDrive[3] = { ustrRelSysPath[0], ':', 0 }; // just "C:" - osl::LongPathBuffer<wchar_t> aBuf(MAX_LONG_PATH); + osl::LongPathBuffer<wchar_t> aBuf(EXTENDED_MAX_PATH); DWORD dwResult = GetFullPathNameW(baseDrive, aBuf.getBufSizeInSymbols(), aBuf, nullptr); if (dwResult) diff --git a/sal/osl/w32/file_url.hxx b/sal/osl/w32/file_url.hxx index 86ce27060db7..cb89b953c00c 100644 --- a/sal/osl/w32/file_url.hxx +++ b/sal/osl/w32/file_url.hxx @@ -44,8 +44,6 @@ #define VALIDATEPATH_ALLOW_RELATIVE 0x0004 #define VALIDATEPATH_ALLOW_INVALID_SPACE_AND_PERIOD 0x0010 -#define MAX_LONG_PATH 32767 - DWORD IsValidFilePath ( const OUString& path, DWORD dwFlags, diff --git a/sal/osl/w32/module.cxx b/sal/osl/w32/module.cxx index e0a2940b16f9..8286f6a095cb 100644 --- a/sal/osl/w32/module.cxx +++ b/sal/osl/w32/module.cxx @@ -29,6 +29,7 @@ #include <rtl/ustring.hxx> #include <sal/log.hxx> #include <o3tl/char16_t2wchar_t.hxx> +#include <systools/win32/extended_max_path.hxx> #include <vector> /* @@ -161,7 +162,7 @@ sal_Bool SAL_CALL osl_getModuleURLFromAddress( void *pv, rtl_uString **pustrURL if (!hModule) return false; - ::osl::LongPathBuffer<sal_Unicode> aBuffer(MAX_LONG_PATH); + osl::LongPathBuffer<sal_Unicode> aBuffer(EXTENDED_MAX_PATH); DWORD nch = GetModuleFileNameW(hModule, o3tl::toW(aBuffer), aBuffer.getBufSizeInSymbols()); diff --git a/sal/osl/w32/process.cxx b/sal/osl/w32/process.cxx index d18513be6dd5..40df459105d9 100644 --- a/sal/osl/w32/process.cxx +++ b/sal/osl/w32/process.cxx @@ -27,6 +27,7 @@ #include <osl/mutex.hxx> #include <osl/nlsupport.h> #include <o3tl/char16_t2wchar_t.hxx> +#include <systools/win32/extended_max_path.hxx> #include "filetime.hxx" #include "nlsupport.hxx" @@ -282,7 +283,7 @@ oslProcessError bootstrap_getExecutableFile(rtl_uString ** ppFileURL) { oslProcessError result = osl_Process_E_NotFound; - ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + osl::LongPathBuffer<sal_Unicode> aBuffer(EXTENDED_MAX_PATH); DWORD buflen = 0; if ((buflen = GetModuleFileNameW (nullptr, o3tl::toW(aBuffer), aBuffer.getBufSizeInSymbols())) > 0) @@ -336,7 +337,7 @@ static rtl_uString ** osl_createCommandArgs_Impl (int argc, char **) if (ppArgs[0] != nullptr) { /* Ensure absolute path */ - ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + osl::LongPathBuffer<sal_Unicode> aBuffer(EXTENDED_MAX_PATH); DWORD dwResult = GetModuleFileNameW(nullptr, o3tl::toW(aBuffer), aBuffer.getBufSizeInSymbols()); if ((0 < dwResult) && (dwResult < aBuffer.getBufSizeInSymbols())) @@ -471,7 +472,7 @@ oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString *ustrVar) oslProcessError SAL_CALL osl_getProcessWorkingDir( rtl_uString **pustrWorkingDir ) { - ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + osl::LongPathBuffer<sal_Unicode> aBuffer(EXTENDED_MAX_PATH); DWORD dwLen = GetCurrentDirectoryW(aBuffer.getBufSizeInSymbols(), o3tl::toW(aBuffer)); if ( dwLen && dwLen < aBuffer.getBufSizeInSymbols() ) diff --git a/sal/osl/w32/profile.cxx b/sal/osl/w32/profile.cxx index 4a0fa385a565..e5fbfe55d188 100644 --- a/sal/osl/w32/profile.cxx +++ b/sal/osl/w32/profile.cxx @@ -32,6 +32,8 @@ #include <sal/macros.h> #include <sal/log.hxx> #include <o3tl/char16_t2wchar_t.hxx> +#include <systools/win32/extended_max_path.hxx> + #include <algorithm> #include <vector> using std::min; @@ -764,8 +766,8 @@ sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const char bool osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName) { bool bFailed; - ::osl::LongPathBuffer< sal_Unicode > aFile( MAX_LONG_PATH ); - ::osl::LongPathBuffer< sal_Unicode > aPath( MAX_LONG_PATH ); + osl::LongPathBuffer<sal_Unicode> aFile(EXTENDED_MAX_PATH); + osl::LongPathBuffer<sal_Unicode> aPath(EXTENDED_MAX_PATH); sal_uInt32 nFileLen = 0; sal_uInt32 nPathLen = 0; @@ -2001,7 +2003,7 @@ static bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *strFile char Buffer[4096] = ""; char Product[132] = ""; - ::osl::LongPathBuffer< sal_Unicode > aPath( MAX_LONG_PATH ); + osl::LongPathBuffer<sal_Unicode> aPath(EXTENDED_MAX_PATH); aPath[0] = 0; if (*strPath == L'"') @@ -2035,7 +2037,7 @@ static bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *strFile rtl_uString * strSVFallback = nullptr; rtl_uString * strSVLocation = nullptr; rtl_uString * strSVName = nullptr; - ::osl::LongPathBuffer< char > aDir( MAX_LONG_PATH ); + osl::LongPathBuffer<char> aDir(EXTENDED_MAX_PATH); oslProfile hProfile; rtl_uString_newFromAscii(&strSVFallback, SVERSION_FALLBACK); @@ -2184,7 +2186,7 @@ static bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *strFile } { - ::osl::LongPathBuffer< char > aTmpPath( MAX_LONG_PATH ); + osl::LongPathBuffer<char> aTmpPath(EXTENDED_MAX_PATH); WideCharToMultiByte(CP_ACP,0, o3tl::toW(aPath), -1, aTmpPath, aTmpPath.getBufSizeInSymbols(), nullptr, nullptr); @@ -2233,7 +2235,7 @@ static bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *strFile copy_ustr_n(aPath + dwPathLen, strFile, rtl_ustr_getLength(strFile)+1); { - ::osl::LongPathBuffer< char > aTmpPath( MAX_LONG_PATH ); + osl::LongPathBuffer<char> aTmpPath(EXTENDED_MAX_PATH); WideCharToMultiByte(CP_ACP,0, o3tl::toW(aPath), -1, aTmpPath, aTmpPath.getBufSizeInSymbols(), nullptr, nullptr); @@ -2301,7 +2303,7 @@ static bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *strFile } else { - ::osl::LongPathBuffer< char > aTmpPath2( MAX_LONG_PATH ); + osl::LongPathBuffer<char> aTmpPath2(EXTENDED_MAX_PATH); int n; if ((n = WideCharToMultiByte( diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx index 30f879573de4..5dcdf42f768c 100644 --- a/sal/osl/w32/tempfile.cxx +++ b/sal/osl/w32/tempfile.cxx @@ -17,6 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <systools/win32/extended_max_path.hxx> #include <systools/win32/uwinapi.h> #include <osl/file.h> @@ -220,7 +223,7 @@ oslFileError SAL_CALL osl_createTempFile( oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) { - ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + osl::LongPathBuffer<sal_Unicode> aBuffer(EXTENDED_MAX_PATH); LPWSTR lpBuffer = o3tl::toW(aBuffer); DWORD nBufferLength = aBuffer.getBufSizeInSymbols() - 1; diff --git a/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx b/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx index 10c817169a27..9d44cfc6b72e 100644 --- a/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx +++ b/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx @@ -20,6 +20,7 @@ #include "shlxtmsi.hxx" #include <algorithm> #include <sstream> +#include <systools/win32/extended_max_path.hxx> #include <systools/win32/uwinapi.h> extern "C" __declspec(dllexport) UINT __stdcall MigrateInstallPath(MSIHANDLE handle) @@ -30,7 +31,7 @@ extern "C" __declspec(dllexport) UINT __stdcall MigrateInstallPath(MSIHANDLE han auto RegValue = [](HKEY hRoot, const WCHAR* sKey, const WCHAR* sVal) { std::wstring sResult; - WCHAR buf[32767]; // max longpath + WCHAR buf[EXTENDED_MAX_PATH]; // max longpath DWORD bufsize = sizeof(buf); // yes, it is the number of bytes if (RegGetValueW(hRoot, sKey, sVal, RRF_RT_REG_SZ, nullptr, buf, &bufsize) == ERROR_SUCCESS) sResult = buf; // RegGetValueW null-terminates strings diff --git a/shell/source/win32/SysShExec.cxx b/shell/source/win32/SysShExec.cxx index 79310d131e72..5e56b39692ce 100644 --- a/shell/source/win32/SysShExec.cxx +++ b/shell/source/win32/SysShExec.cxx @@ -43,6 +43,7 @@ #include <prewin.h> #include <Shlobj.h> #include <systools/win32/comtools.hxx> +#include <systools/win32/extended_max_path.hxx> #include <postwin.h> using namespace ::com::sun::star::system::SystemShellExecuteFlags; @@ -210,13 +211,12 @@ BOOL CALLBACK FindAndActivateProcWnd(HWND hwnd, LPARAM lParam) OUString checkFile(const OUString& pathname, const OUString& aCommand) { - const int MAX_LONG_PATH = 32767; // max longpath on WinNT - if (pathname.getLength() >= MAX_LONG_PATH) + if (pathname.getLength() >= EXTENDED_MAX_PATH) { throw css::lang::IllegalArgumentException( "XSystemShellExecute.execute, path <" + pathname + "> too long", {}, 0); } - wchar_t path[MAX_LONG_PATH]; + wchar_t path[EXTENDED_MAX_PATH]; wcscpy_s(path, o3tl::toW(pathname.getStr())); for (int i = 0;; ++i) { // tdf#130216: normalize c:\path o\something\..lse into c:\path olse diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 13c7b8f8bc0a..5f775e7a3d96 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -72,6 +72,7 @@ #include <postwin.h> #include <o3tl/char16_t2wchar_t.hxx> #include <osl/file.hxx> +#include <systools/win32/extended_max_path.hxx> #endif #include <svx/unomodel.hxx> @@ -2902,10 +2903,10 @@ bool SwTransferable::PasteGrf( const TransferableDataHelper& rData, SwWrtShell& // tdf#124500: Convert short path to long path which should be used in links OUString sSysPath; osl::FileBase::getSystemPathFromFileURL(sText, sSysPath); - std::unique_ptr<sal_Unicode[]> aBuf(new sal_Unicode[32767]); + std::unique_ptr<sal_Unicode[]> aBuf(new sal_Unicode[EXTENDED_MAX_PATH]); DWORD nCopied = GetLongPathNameW(o3tl::toW(sSysPath.getStr()), - o3tl::toW(aBuf.get()), 32767); - if (nCopied && nCopied < 32767) + o3tl::toW(aBuf.get()), EXTENDED_MAX_PATH); + if (nCopied && nCopied < EXTENDED_MAX_PATH) sText = URIHelper::SmartRel2Abs(INetURLObject(), OUString(aBuf.get()), Link<OUString*, bool>(), false); } diff --git a/vcl/win/app/fileregistration.cxx b/vcl/win/app/fileregistration.cxx index 9e72e5bf03a0..31a3d996ed72 100644 --- a/vcl/win/app/fileregistration.cxx +++ b/vcl/win/app/fileregistration.cxx @@ -24,11 +24,10 @@ #include <prewin.h> #include <Shobjidl.h> #include <systools/win32/comtools.hxx> +#include <systools/win32/extended_max_path.hxx> #include <versionhelpers.h> #include <postwin.h> -#define MAX_LONG_PATH 32767 - namespace vcl::fileregistration { static void LaunchModernSettingsDialogDefaultApps() @@ -75,25 +74,25 @@ static bool IsDefaultAppInstalledInReg() { const wchar_t* keyPath = L"SOFTWARE\LibreOffice\UNO\InstallPath"; - WCHAR szRegPath[MAX_LONG_PATH]; - DWORD cbData = static_cast<DWORD>(MAX_LONG_PATH * sizeof(WCHAR)); - auto rc = RegGetValueW(HKEY_LOCAL_MACHINE, keyPath, nullptr, RRF_RT_REG_SZ, nullptr, - static_cast<PVOID>(szRegPath), &cbData); + WCHAR szRegPath[EXTENDED_MAX_PATH]; + DWORD cbData = sizeof(szRegPath); + auto rc = RegGetValueW(HKEY_LOCAL_MACHINE, keyPath, nullptr, RRF_RT_REG_SZ, nullptr, szRegPath, + &cbData); if (rc != ERROR_SUCCESS) return false; - WCHAR szProcPath[MAX_LONG_PATH]; - if (!GetModuleFileNameW(nullptr, szProcPath, MAX_LONG_PATH)) + WCHAR szProcPath[EXTENDED_MAX_PATH]; + if (!GetModuleFileNameW(nullptr, szProcPath, EXTENDED_MAX_PATH)) return false; - WCHAR szFullProcPath[MAX_LONG_PATH]; - if (!GetFullPathNameW(szProcPath, MAX_LONG_PATH, szFullProcPath, nullptr)) + WCHAR szFullProcPath[EXTENDED_MAX_PATH]; + if (!GetFullPathNameW(szProcPath, EXTENDED_MAX_PATH, szFullProcPath, nullptr)) return false; - if (!GetLongPathNameW(szFullProcPath, szFullProcPath, MAX_LONG_PATH)) + if (!GetLongPathNameW(szFullProcPath, szFullProcPath, EXTENDED_MAX_PATH)) return false; - if (!GetLongPathNameW(szRegPath, szRegPath, MAX_LONG_PATH)) + if (!GetLongPathNameW(szRegPath, szRegPath, EXTENDED_MAX_PATH)) return false; if (wcslen(szRegPath) > 0 && wcsstr(szFullProcPath, szRegPath) != nullptr)
