Skip to content

Commit 2da2fba

Browse files
authored
[SHELL32][SHELL32_APITEST][SDK] Implement SHSetUnreadMailCountW (reactos#7620)
Implementing missing features... JIRA issue: CORE-19278 - Move function definition from stubs.cpp into utils.cpp. - Add prototype to <shellapi.h>.
1 parent dc25409 commit 2da2fba

File tree

6 files changed

+125
-13
lines changed

6 files changed

+125
-13
lines changed

dll/win32/shell32/stubs.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@ SHGetUnreadMailCountW(HKEY hKeyUser,
3030
return E_FAIL;
3131
}
3232

33-
/*
34-
* Unimplemented
35-
*/
36-
EXTERN_C HRESULT
37-
WINAPI
38-
SHSetUnreadMailCountW(LPCWSTR pszMailAddress,
39-
DWORD dwCount,
40-
LPCWSTR pszShellExecuteCommand)
41-
{
42-
FIXME("SHSetUnreadMailCountW() stub\n");
43-
return E_FAIL;
44-
}
45-
4633
/*
4734
* Unimplemented
4835
*/

dll/win32/shell32/utils.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,64 @@ SHCreatePropertyBag(_In_ REFIID riid, _Out_ void **ppvObj)
796796
return SHCreatePropertyBagOnMemory(STGM_READWRITE, riid, ppvObj);
797797
}
798798

799+
/*************************************************************************
800+
* SHSetUnreadMailCountW [SHELL32.336]
801+
*
802+
* @see https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shsetunreadmailcountw
803+
*/
804+
EXTERN_C
805+
HRESULT WINAPI
806+
SHSetUnreadMailCountW(
807+
_In_ PCWSTR pszMailAddress,
808+
_In_ DWORD dwCount,
809+
_In_ PCWSTR pszShellExecuteCommand)
810+
{
811+
CString strKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\UnreadMail";
812+
strKey += L'\\';
813+
strKey += pszMailAddress;
814+
815+
HKEY hKey;
816+
DWORD dwDisposition;
817+
LSTATUS error = RegCreateKeyExW(HKEY_CURRENT_USER, strKey, 0, NULL, 0, KEY_SET_VALUE, NULL,
818+
&hKey, &dwDisposition);
819+
if (error)
820+
return HRESULT_FROM_WIN32(error);
821+
822+
error = RegSetValueExW(hKey, L"MessageCount", 0, REG_DWORD, (PBYTE)&dwCount, sizeof(dwCount));
823+
if (error)
824+
{
825+
RegCloseKey(hKey);
826+
return HRESULT_FROM_WIN32(error);
827+
}
828+
829+
FILETIME FileTime;
830+
GetSystemTimeAsFileTime(&FileTime);
831+
832+
error = RegSetValueExW(hKey, L"TimeStamp", 0, REG_BINARY, (PBYTE)&FileTime, sizeof(FileTime));
833+
if (error)
834+
{
835+
RegCloseKey(hKey);
836+
return HRESULT_FROM_WIN32(error);
837+
}
838+
839+
WCHAR szBuff[2 * MAX_PATH];
840+
if (!PathUnExpandEnvStringsW(pszShellExecuteCommand, szBuff, _countof(szBuff)))
841+
{
842+
HRESULT hr = StringCchCopyW(szBuff, _countof(szBuff), pszShellExecuteCommand);
843+
if (FAILED_UNEXPECTEDLY(hr))
844+
{
845+
RegCloseKey(hKey);
846+
return hr;
847+
}
848+
}
849+
850+
DWORD cbValue = (lstrlenW(szBuff) + 1) * sizeof(WCHAR);
851+
error = RegSetValueExW(hKey, L"Application", 0, REG_SZ, (PBYTE)szBuff, cbValue);
852+
853+
RegCloseKey(hKey);
854+
return (error ? HRESULT_FROM_WIN32(error) : S_OK);
855+
}
856+
799857
/*************************************************************************
800858
* SheRemoveQuotesA (SHELL32.@)
801859
*/

modules/rostests/apitests/shell32/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ list(APPEND SOURCE
4545
SHGetAttributesFromDataObject.cpp
4646
SHGetUserDisplayName.cpp
4747
SHLimitInputEdit.cpp
48+
SHSetUnreadMailCountW.cpp
4849
menu.cpp
4950
shelltest.cpp)
5051

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* PROJECT: ReactOS API tests
3+
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4+
* PURPOSE: Test for SHSetUnreadMailCountW
5+
* COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ ([email protected])
6+
*/
7+
8+
#include "shelltest.h"
9+
10+
START_TEST(SHSetUnreadMailCountW)
11+
{
12+
HKEY hKey;
13+
LSTATUS error;
14+
DWORD dwDisposition;
15+
error = RegCreateKeyExW(HKEY_CURRENT_USER,
16+
L"Software\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\example.com",
17+
0, NULL, 0, KEY_WRITE, NULL, &hKey, &dwDisposition);
18+
ok_long(error, ERROR_SUCCESS);
19+
RegCloseKey(hKey);
20+
21+
HRESULT hr = SHSetUnreadMailCountW(L"example.com", 1, L"MyMailerApp");
22+
ok_hex(hr, S_OK);
23+
24+
error = RegOpenKeyExW(HKEY_CURRENT_USER,
25+
L"Software\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\example.com",
26+
0,
27+
KEY_READ,
28+
&hKey);
29+
ok_long(error, ERROR_SUCCESS);
30+
31+
DWORD dwValue, cbValue = sizeof(dwValue);
32+
error = RegQueryValueExW(hKey, L"MessageCount", NULL, NULL, (PBYTE)&dwValue, &cbValue);
33+
ok_long(error, ERROR_SUCCESS);
34+
ok_long(dwValue, 1);
35+
36+
FILETIME FileTime;
37+
cbValue = sizeof(FileTime);
38+
error = RegQueryValueExW(hKey, L"TimeStamp", NULL, NULL, (PBYTE)&FileTime, &cbValue);
39+
ok_long(error, ERROR_SUCCESS);
40+
ok(FileTime.dwHighDateTime != 0, "FileTime.dwHighDateTime was zero\n");
41+
42+
WCHAR szValue[MAX_PATH];
43+
cbValue = sizeof(szValue);
44+
error = RegQueryValueExW(hKey, L"Application", NULL, NULL, (PBYTE)szValue, &cbValue);
45+
ok_long(error, ERROR_SUCCESS);
46+
ok_wstr(szValue, L"MyMailerApp");
47+
48+
RegCloseKey(hKey);
49+
50+
hr = SHSetUnreadMailCountW(L"example.com", 0, L"MyMailerApp");
51+
ok_hex(hr, S_OK);
52+
53+
if (dwDisposition == REG_CREATED_NEW_KEY)
54+
{
55+
RegDeleteKeyW(HKEY_CURRENT_USER,
56+
L"Software\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\example.com");
57+
}
58+
}

modules/rostests/apitests/shell32/testlist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern void func_SHParseDisplayName(void);
4949
extern void func_SHShouldShowWizards(void);
5050
extern void func_SHSimpleIDListFromPath(void);
5151
extern void func_SHRestricted(void);
52+
extern void func_SHSetUnreadMailCountW(void);
5253

5354
const struct test winetest_testlist[] =
5455
{
@@ -98,6 +99,7 @@ const struct test winetest_testlist[] =
9899
{ "SHShouldShowWizards", func_SHShouldShowWizards },
99100
{ "SHSimpleIDListFromPath", func_SHSimpleIDListFromPath },
100101
{ "SHRestricted", func_SHRestricted },
102+
{ "SHSetUnreadMailCountW", func_SHSetUnreadMailCountW },
101103

102104
{ 0, 0 }
103105
};

sdk/include/psdk/shellapi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ DoEnvironmentSubstW(
638638
_Inout_updates_(cchSrc) LPWSTR pszSrc,
639639
UINT cchSrc);
640640

641+
HRESULT WINAPI
642+
SHSetUnreadMailCountW(
643+
_In_ PCWSTR pszMailAddress,
644+
_In_ DWORD dwCount,
645+
_In_ PCWSTR pszShellExecuteCommand);
646+
641647
#if (_WIN32_IE >= 0x0601)
642648
BOOL
643649
WINAPI

0 commit comments

Comments
 (0)