diff --git a/dll/win32/shell32/utils.cpp b/dll/win32/shell32/utils.cpp index 746ca144036..5b044082662 100644 --- a/dll/win32/shell32/utils.cpp +++ b/dll/win32/shell32/utils.cpp @@ -2262,6 +2262,84 @@ SHELL32_ReparentAsAliasPidl( return (*ppidlNew != NULL); } +/************************************************************************* + * SHSetLocalizedName (SHELL32.@) + * + * https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shsetlocalizedname + */ +EXTERN_C +HRESULT WINAPI +SHSetLocalizedName( + _In_ PCWSTR pszPath, + _In_ PCWSTR pszResModule, + _In_ INT idsRes) +{ + HRESULT hr; + IShellFolder *pDesktop = NULL, *pParent = NULL; + LPITEMIDLIST pidl = NULL; + LPCITEMIDLIST pidlLast; + HANDLE hProcessHeap; + INT cchShortMax, cchShort, cchName; + PWSTR pszShortPath = NULL, pszName = NULL; + + hr = SHCoInitializeAnyApartment(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + hr = SHGetDesktopFolder(&pDesktop); + if (FAILED_UNEXPECTEDLY(hr)) + goto Cleanup; + + hr = pDesktop->ParseDisplayName(NULL, NULL, (PWSTR)pszPath, NULL, &pidl, NULL); + if (FAILED_UNEXPECTEDLY(hr)) + goto Cleanup; + + hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &pParent), &pidlLast); + if (FAILED_UNEXPECTEDLY(hr)) + goto Cleanup; + + hProcessHeap = GetProcessHeap(); + cchShortMax = lstrlenW(pszResModule) + 1; + pszShortPath = (PWSTR)HeapAlloc(hProcessHeap, 0, cchShortMax * sizeof(WCHAR)); + if (!pszShortPath) + { + hr = E_OUTOFMEMORY; + goto Cleanup; + } + + cchShort = GetShortPathNameW(pszResModule, pszShortPath, cchShortMax); + if (cchShort) + pszResModule = pszShortPath; + else + cchShort = cchShortMax; + + /* 14 == '@' + ',' + '-' + (digits of max width 10) + NUL */ + cchName = cchShort + 14; + pszName = (PWSTR)HeapAlloc(hProcessHeap, 0, cchName * sizeof(WCHAR)); + if (!pszName) + { + hr = E_OUTOFMEMORY; + goto Cleanup; + } + + wnsprintfW(pszName, cchName, L"@%s,%d", pszResModule, -idsRes); + hr = pParent->SetNameOf(NULL, pidlLast, pszName, 0, NULL); + +Cleanup: + if (pszName) + HeapFree(hProcessHeap, 0, pszName); + if (pszShortPath) + HeapFree(hProcessHeap, 0, pszShortPath); + if (pParent) + pParent->Release(); + if (pidl) + SHFree(pidl); + if (pDesktop) + pDesktop->Release(); + CoUninitialize(); + return hr; +} + //! Translate a PIDL to an "alias" PIDL. EXTERN_C HRESULT SHELL32_AliasTranslatePidl( diff --git a/dll/win32/shell32/wine/shellord.c b/dll/win32/shell32/wine/shellord.c index 1a39573a372..a613afeb81c 100644 --- a/dll/win32/shell32/wine/shellord.c +++ b/dll/win32/shell32/wine/shellord.c @@ -2630,6 +2630,8 @@ HRESULT WINAPI SHStartNetConnectionDialog(HWND hwnd, LPCSTR pszRemoteName, DWORD return S_OK; #endif } + +#ifndef __REACTOS__ /* See ../utils.cpp */ /************************************************************************* * SHSetLocalizedName (SHELL32.@) */ @@ -2639,6 +2641,7 @@ HRESULT WINAPI SHSetLocalizedName(LPCWSTR pszPath, LPCWSTR pszResModule, int ids return S_OK; } +#endif #ifndef __REACTOS__ // See ../utils.cpp /************************************************************************* diff --git a/sdk/include/psdk/shellapi.h b/sdk/include/psdk/shellapi.h index ba9fda4585e..331da984854 100644 --- a/sdk/include/psdk/shellapi.h +++ b/sdk/include/psdk/shellapi.h @@ -684,6 +684,12 @@ SHGetUnreadMailCountW( _Out_writes_opt_(cchShellExecuteCommand) PWSTR pszShellExecuteCommand, _In_ INT cchShellExecuteCommand); +HRESULT WINAPI +SHSetLocalizedName( + _In_ PCWSTR pszPath, + _In_ PCWSTR pszResModule, + _In_ INT idsRes); + #ifdef UNICODE #define NOTIFYICONDATA_V1_SIZE NOTIFYICONDATAW_V1_SIZE #define NOTIFYICONDATA_V2_SIZE NOTIFYICONDATAW_V2_SIZE