[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

@ -120,7 +120,7 @@ set_source_files_properties(shell32.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT
set_module_type(shell32 win32dll UNICODE) set_module_type(shell32 win32dll UNICODE)
target_link_libraries(shell32 shellmenu shelldesktop wine uuid recyclebin cpprt atl_classes oldnames) target_link_libraries(shell32 shellmenu shelldesktop wine uuid recyclebin cpprt atl_classes oldnames)
add_delay_importlibs(shell32 powrprof shdocvw devmgr winspool.drv winmm mpr uxtheme ole32 oleaut32 userenv browseui version fmifs) add_delay_importlibs(shell32 powrprof shdocvw devmgr winspool.drv winmm mpr uxtheme ole32 oleaut32 userenv browseui version fmifs netapi32 secur32)
add_importlibs(shell32 advapi32 gdi32 user32 comctl32 comdlg32 shlwapi msvcrt kernel32 ntdll) add_importlibs(shell32 advapi32 gdi32 user32 comctl32 comdlg32 shlwapi msvcrt kernel32 ntdll)
add_dependencies(shell32 stdole2) # shell32_shldisp.tlb needs stdole2.tlb add_dependencies(shell32 stdole2) # shell32_shldisp.tlb needs stdole2.tlb
add_pch(shell32 precomp.h "${PCH_SKIP_SOURCE}") add_pch(shell32 precomp.h "${PCH_SKIP_SOURCE}")

View file

@ -920,18 +920,6 @@ PathIsSlowW(
return FALSE; return FALSE;
} }
/*
* Unimplemented
*/
EXTERN_C DWORD
WINAPI
SHGetUserDisplayName(LPWSTR lpName, PULONG puSize)
{
FIXME("SHGetUserDisplayName() stub\n");
wcscpy(lpName, L"UserName");
return ERROR_SUCCESS;
}
/* /*
* Unimplemented * Unimplemented
*/ */

View file

@ -6,6 +6,10 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <lmcons.h>
#include <lmapibuf.h>
#include <lmaccess.h>
#include <secext.h>
WINE_DEFAULT_DEBUG_CHANNEL(shell); WINE_DEFAULT_DEBUG_CHANNEL(shell);
@ -1485,3 +1489,64 @@ SHELL_CreateShell32DefaultExtractIcon(int IconIndex, REFIID riid, LPVOID *ppvOut
initIcon->SetNormalIcon(swShell32Name, IconIndex); initIcon->SetNormalIcon(swShell32Name, IconIndex);
return initIcon->QueryInterface(riid, ppvOut); 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;
}

View file

@ -41,6 +41,7 @@ list(APPEND SOURCE
ShellInfo.cpp ShellInfo.cpp
ShellState.cpp ShellState.cpp
SHGetAttributesFromDataObject.cpp SHGetAttributesFromDataObject.cpp
SHGetUserDisplayName.cpp
SHLimitInputEdit.cpp SHLimitInputEdit.cpp
menu.cpp menu.cpp
shelltest.cpp) shelltest.cpp)

View file

@ -0,0 +1,30 @@
/*
* PROJECT: ReactOS API tests
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Test for SHGetUserDisplayName
* COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
*/
#include "shelltest.h"
#include <undocshell.h>
START_TEST(SHGetUserDisplayName)
{
HRESULT hr;
WCHAR szBuf[MAX_PATH];
ULONG cchBuf;
hr = SHGetUserDisplayName(NULL, NULL);
ok_hex(hr, E_INVALIDARG);
hr = SHGetUserDisplayName(szBuf, NULL);
ok_hex(hr, E_INVALIDARG);
cchBuf = _countof(szBuf);
hr = SHGetUserDisplayName(NULL, &cchBuf);
ok_hex(hr, E_INVALIDARG);
cchBuf = _countof(szBuf);
hr = SHGetUserDisplayName(szBuf, &cchBuf);
ok_hex(hr, S_OK);
}

View file

@ -42,6 +42,7 @@ extern void func_ShellHook(void);
extern void func_ShellState(void); extern void func_ShellState(void);
extern void func_SHGetAttributesFromDataObject(void); extern void func_SHGetAttributesFromDataObject(void);
extern void func_SHGetFileInfo(void); extern void func_SHGetFileInfo(void);
extern void func_SHGetUserDisplayName(void);
extern void func_SHLimitInputEdit(void); extern void func_SHLimitInputEdit(void);
extern void func_SHParseDisplayName(void); extern void func_SHParseDisplayName(void);
extern void func_SHSimpleIDListFromPath(void); extern void func_SHSimpleIDListFromPath(void);
@ -88,6 +89,7 @@ const struct test winetest_testlist[] =
{ "ShellState", func_ShellState }, { "ShellState", func_ShellState },
{ "SHGetAttributesFromDataObject", func_SHGetAttributesFromDataObject }, { "SHGetAttributesFromDataObject", func_SHGetAttributesFromDataObject },
{ "SHGetFileInfo", func_SHGetFileInfo }, { "SHGetFileInfo", func_SHGetFileInfo },
{ "SHGetUserDisplayName", func_SHGetUserDisplayName },
{ "SHLimitInputEdit", func_SHLimitInputEdit }, { "SHLimitInputEdit", func_SHLimitInputEdit },
{ "SHParseDisplayName", func_SHParseDisplayName }, { "SHParseDisplayName", func_SHParseDisplayName },
{ "SHSimpleIDListFromPath", func_SHSimpleIDListFromPath }, { "SHSimpleIDListFromPath", func_SHSimpleIDListFromPath },

View file

@ -1,8 +1,13 @@
#ifndef _SECEXT_H #ifndef _SECEXT_H
#define _SECEXT_H #define _SECEXT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef RC_INVOKED #ifndef RC_INVOKED
#if (_WIN32_WINNT >= 0x0500) #if (_WIN32_WINNT >= 0x0500)
typedef enum typedef enum
{ {
NameUnknown = 0, NameUnknown = 0,
@ -34,7 +39,11 @@ BOOLEAN WINAPI TranslateNameW(LPCWSTR,EXTENDED_NAME_FORMAT,EXTENDED_NAME_FORMAT,
#define TranslateName TranslateNameA #define TranslateName TranslateNameA
#endif #endif
#endif /* ! RC_INVOKED */ #endif /* ! RC_INVOKED */
#endif /* _WIN32_WINNT >= 0x0500 */ #endif /* _WIN32_WINNT >= 0x0500 */
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* ! _SECEXT_H */ #endif /* ! _SECEXT_H */

View file

@ -211,6 +211,11 @@ DWORD WINAPI SHNetConnectionDialog(
BOOL WINAPI SHIsTempDisplayMode(VOID); BOOL WINAPI SHIsTempDisplayMode(VOID);
HRESULT WINAPI
SHGetUserDisplayName(
_Out_writes_to_(*puSize, *puSize) PWSTR pName,
_Inout_ PULONG puSize);
/**************************************************************************** /****************************************************************************
* Cabinet Window Messages * Cabinet Window Messages
*/ */