Skip to content

Commit fcbcaa1

Browse files
authored
[SHELL32][SHELL32_APITEST][SDK] Implement SHGetUserDisplayName (reactos#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>.
1 parent ee5ff8c commit fcbcaa1

File tree

8 files changed

+114
-14
lines changed

8 files changed

+114
-14
lines changed

dll/win32/shell32/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ set_source_files_properties(shell32.rc PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT
120120

121121
set_module_type(shell32 win32dll UNICODE)
122122
target_link_libraries(shell32 shellmenu shelldesktop wine uuid recyclebin cpprt atl_classes oldnames)
123-
add_delay_importlibs(shell32 powrprof shdocvw devmgr winspool.drv winmm mpr uxtheme ole32 oleaut32 userenv browseui version fmifs)
123+
add_delay_importlibs(shell32 powrprof shdocvw devmgr winspool.drv winmm mpr uxtheme ole32 oleaut32 userenv browseui version fmifs netapi32 secur32)
124124
add_importlibs(shell32 advapi32 gdi32 user32 comctl32 comdlg32 shlwapi msvcrt kernel32 ntdll)
125125
add_dependencies(shell32 stdole2) # shell32_shldisp.tlb needs stdole2.tlb
126126
add_pch(shell32 precomp.h "${PCH_SKIP_SOURCE}")

dll/win32/shell32/stubs.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -920,18 +920,6 @@ PathIsSlowW(
920920
return FALSE;
921921
}
922922

923-
/*
924-
* Unimplemented
925-
*/
926-
EXTERN_C DWORD
927-
WINAPI
928-
SHGetUserDisplayName(LPWSTR lpName, PULONG puSize)
929-
{
930-
FIXME("SHGetUserDisplayName() stub\n");
931-
wcscpy(lpName, L"UserName");
932-
return ERROR_SUCCESS;
933-
}
934-
935923
/*
936924
* Unimplemented
937925
*/

dll/win32/shell32/utils.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
*/
77

88
#include "precomp.h"
9+
#include <lmcons.h>
10+
#include <lmapibuf.h>
11+
#include <lmaccess.h>
12+
#include <secext.h>
913

1014
WINE_DEFAULT_DEBUG_CHANNEL(shell);
1115

@@ -1485,3 +1489,64 @@ SHELL_CreateShell32DefaultExtractIcon(int IconIndex, REFIID riid, LPVOID *ppvOut
14851489
initIcon->SetNormalIcon(swShell32Name, IconIndex);
14861490
return initIcon->QueryInterface(riid, ppvOut);
14871491
}
1492+
1493+
/*************************************************************************
1494+
* SHGetUserDisplayName [SHELL32.241]
1495+
*
1496+
* @see https://undoc.airesoft.co.uk/shell32.dll/SHGetUserDisplayName.php
1497+
*/
1498+
EXTERN_C
1499+
HRESULT WINAPI
1500+
SHGetUserDisplayName(
1501+
_Out_writes_to_(*puSize, *puSize) PWSTR pName,
1502+
_Inout_ PULONG puSize)
1503+
{
1504+
if (!pName || !puSize)
1505+
return E_INVALIDARG;
1506+
1507+
if (GetUserNameExW(NameDisplay, pName, puSize))
1508+
return S_OK;
1509+
1510+
LONG error = GetLastError(); // for ERROR_NONE_MAPPED
1511+
HRESULT hr = HRESULT_FROM_WIN32(error);
1512+
1513+
WCHAR UserName[MAX_PATH];
1514+
DWORD cchUserName = _countof(UserName);
1515+
if (!GetUserNameW(UserName, &cchUserName))
1516+
return HRESULT_FROM_WIN32(GetLastError());
1517+
1518+
// Was the user name not available in the specified format (NameDisplay)?
1519+
if (error == ERROR_NONE_MAPPED)
1520+
{
1521+
// Try to get the user name by using Network API
1522+
PUSER_INFO_2 UserInfo;
1523+
DWORD NetError = NetUserGetInfo(NULL, UserName, 2, (PBYTE*)&UserInfo);
1524+
if (NetError)
1525+
{
1526+
hr = HRESULT_FROM_WIN32(NetError);
1527+
}
1528+
else
1529+
{
1530+
if (UserInfo->usri2_full_name)
1531+
{
1532+
hr = StringCchCopyW(pName, *puSize, UserInfo->usri2_full_name);
1533+
if (SUCCEEDED(hr))
1534+
{
1535+
// Include the NUL-terminator
1536+
*puSize = lstrlenW(UserInfo->usri2_full_name) + 1;
1537+
}
1538+
}
1539+
1540+
NetApiBufferFree(UserInfo);
1541+
}
1542+
}
1543+
1544+
if (FAILED(hr))
1545+
{
1546+
hr = StringCchCopyW(pName, *puSize, UserName);
1547+
if (SUCCEEDED(hr))
1548+
*puSize = cchUserName;
1549+
}
1550+
1551+
return hr;
1552+
}

modules/rostests/apitests/shell32/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ list(APPEND SOURCE
4141
ShellInfo.cpp
4242
ShellState.cpp
4343
SHGetAttributesFromDataObject.cpp
44+
SHGetUserDisplayName.cpp
4445
SHLimitInputEdit.cpp
4546
menu.cpp
4647
shelltest.cpp)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* PROJECT: ReactOS API tests
3+
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4+
* PURPOSE: Test for SHGetUserDisplayName
5+
* COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ ([email protected])
6+
*/
7+
8+
#include "shelltest.h"
9+
#include <undocshell.h>
10+
11+
START_TEST(SHGetUserDisplayName)
12+
{
13+
HRESULT hr;
14+
WCHAR szBuf[MAX_PATH];
15+
ULONG cchBuf;
16+
17+
hr = SHGetUserDisplayName(NULL, NULL);
18+
ok_hex(hr, E_INVALIDARG);
19+
20+
hr = SHGetUserDisplayName(szBuf, NULL);
21+
ok_hex(hr, E_INVALIDARG);
22+
23+
cchBuf = _countof(szBuf);
24+
hr = SHGetUserDisplayName(NULL, &cchBuf);
25+
ok_hex(hr, E_INVALIDARG);
26+
27+
cchBuf = _countof(szBuf);
28+
hr = SHGetUserDisplayName(szBuf, &cchBuf);
29+
ok_hex(hr, S_OK);
30+
}

modules/rostests/apitests/shell32/testlist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern void func_ShellHook(void);
4242
extern void func_ShellState(void);
4343
extern void func_SHGetAttributesFromDataObject(void);
4444
extern void func_SHGetFileInfo(void);
45+
extern void func_SHGetUserDisplayName(void);
4546
extern void func_SHLimitInputEdit(void);
4647
extern void func_SHParseDisplayName(void);
4748
extern void func_SHSimpleIDListFromPath(void);
@@ -88,6 +89,7 @@ const struct test winetest_testlist[] =
8889
{ "ShellState", func_ShellState },
8990
{ "SHGetAttributesFromDataObject", func_SHGetAttributesFromDataObject },
9091
{ "SHGetFileInfo", func_SHGetFileInfo },
92+
{ "SHGetUserDisplayName", func_SHGetUserDisplayName },
9193
{ "SHLimitInputEdit", func_SHLimitInputEdit },
9294
{ "SHParseDisplayName", func_SHParseDisplayName },
9395
{ "SHSimpleIDListFromPath", func_SHSimpleIDListFromPath },

sdk/include/psdk/secext.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#ifndef _SECEXT_H
22
#define _SECEXT_H
33

4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
48
#ifndef RC_INVOKED
59
#if (_WIN32_WINNT >= 0x0500)
10+
611
typedef enum
712
{
813
NameUnknown = 0,
@@ -34,7 +39,11 @@ BOOLEAN WINAPI TranslateNameW(LPCWSTR,EXTENDED_NAME_FORMAT,EXTENDED_NAME_FORMAT,
3439
#define TranslateName TranslateNameA
3540
#endif
3641

37-
3842
#endif /* ! RC_INVOKED */
3943
#endif /* _WIN32_WINNT >= 0x0500 */
44+
45+
#ifdef __cplusplus
46+
} // extern "C"
47+
#endif
48+
4049
#endif /* ! _SECEXT_H */

sdk/include/reactos/undocshell.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ DWORD WINAPI SHNetConnectionDialog(
211211

212212
BOOL WINAPI SHIsTempDisplayMode(VOID);
213213

214+
HRESULT WINAPI
215+
SHGetUserDisplayName(
216+
_Out_writes_to_(*puSize, *puSize) PWSTR pName,
217+
_Inout_ PULONG puSize);
218+
214219
/****************************************************************************
215220
* Cabinet Window Messages
216221
*/

0 commit comments

Comments
 (0)