mirror of
https://github.com/reactos/reactos.git
synced 2026-05-31 08:17:09 +08:00
[SHELL32][SDK] Implement SHSetLocalizedName (#8879)
Implementing missing features... Renaming My Computer's name etc.. JIRA issue: CORE-19278 - Implement SHSetLocalizedName function. - Add prototype to <shellapi.h>. Co-authored-by: Vitaly Orekhov <vkvo2000@vivaldi.net> Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
This commit is contained in:
committed by
GitHub
parent
5ab1ff188c
commit
07d544ff07
@@ -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(
|
||||
|
||||
@@ -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
|
||||
/*************************************************************************
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user