[SHELL32][SHELL32_APITEST][SDK] Implement SHGetUserDisplayName (#7612)

Implemementing missing features...
JIRA issue: CORE-19278
- Add netapi32 and secur32 delay importing.
- Move function definition from stubs.cpp into utils.cpp.
- Include some security headers in utils.cpp.
- Adapt <secext.h> to C++.
- Add prototype to <undocshell.h>.
This commit is contained in:
Katayama Hirofumi MZ 2025-01-17 09:33:52 +09:00 committed by GitHub
parent ee5ff8ce0c
commit fcbcaa10a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 114 additions and 14 deletions

View file

@ -6,6 +6,10 @@
*/
#include "precomp.h"
#include <lmcons.h>
#include <lmapibuf.h>
#include <lmaccess.h>
#include <secext.h>
WINE_DEFAULT_DEBUG_CHANNEL(shell);
@ -1485,3 +1489,64 @@ SHELL_CreateShell32DefaultExtractIcon(int IconIndex, REFIID riid, LPVOID *ppvOut
initIcon->SetNormalIcon(swShell32Name, IconIndex);
return initIcon->QueryInterface(riid, ppvOut);
}
/*************************************************************************
* SHGetUserDisplayName [SHELL32.241]
*
* @see https://undoc.airesoft.co.uk/shell32.dll/SHGetUserDisplayName.php
*/
EXTERN_C
HRESULT WINAPI
SHGetUserDisplayName(
_Out_writes_to_(*puSize, *puSize) PWSTR pName,
_Inout_ PULONG puSize)
{
if (!pName || !puSize)
return E_INVALIDARG;
if (GetUserNameExW(NameDisplay, pName, puSize))
return S_OK;
LONG error = GetLastError(); // for ERROR_NONE_MAPPED
HRESULT hr = HRESULT_FROM_WIN32(error);
WCHAR UserName[MAX_PATH];
DWORD cchUserName = _countof(UserName);
if (!GetUserNameW(UserName, &cchUserName))
return HRESULT_FROM_WIN32(GetLastError());
// Was the user name not available in the specified format (NameDisplay)?
if (error == ERROR_NONE_MAPPED)
{
// Try to get the user name by using Network API
PUSER_INFO_2 UserInfo;
DWORD NetError = NetUserGetInfo(NULL, UserName, 2, (PBYTE*)&UserInfo);
if (NetError)
{
hr = HRESULT_FROM_WIN32(NetError);
}
else
{
if (UserInfo->usri2_full_name)
{
hr = StringCchCopyW(pName, *puSize, UserInfo->usri2_full_name);
if (SUCCEEDED(hr))
{
// Include the NUL-terminator
*puSize = lstrlenW(UserInfo->usri2_full_name) + 1;
}
}
NetApiBufferFree(UserInfo);
}
}
if (FAILED(hr))
{
hr = StringCchCopyW(pName, *puSize, UserName);
if (SUCCEEDED(hr))
*puSize = cchUserName;
}
return hr;
}