From 1d5d93f05f481f49ff67b927b4f174fe7c7edfe7 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Sun, 14 Jun 2026 11:12:21 +0900 Subject: [PATCH] [SHLWAPI][SHLWAPI_APITEST][SDK] Support MapWin32ErrorToSTG (#9147) Implementing missing features... JIRA issue: CORE-19278 - Implement MapWin32ErrorToSTG function. - Modify shlwapi.spec. - Add prototype to . - Add MapWin32ErrorToSTG testcase. --- dll/win32/shlwapi/shlwapi.spec | 2 +- dll/win32/shlwapi/utils.cpp | 23 ++++++++++ .../rostests/apitests/shlwapi/CMakeLists.txt | 1 + .../apitests/shlwapi/MapWin32ErrorToSTG.c | 45 +++++++++++++++++++ modules/rostests/apitests/shlwapi/testlist.c | 2 + sdk/include/reactos/shlwapi_undoc.h | 2 + 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 modules/rostests/apitests/shlwapi/MapWin32ErrorToSTG.c diff --git a/dll/win32/shlwapi/shlwapi.spec b/dll/win32/shlwapi/shlwapi.spec index 7db1f80e104..546d830109e 100644 --- a/dll/win32/shlwapi/shlwapi.spec +++ b/dll/win32/shlwapi/shlwapi.spec @@ -482,7 +482,7 @@ 482 stub -noname SHMessageBoxHelpA 483 stub -noname SHMessageBoxHelpW 484 stdcall -noname IUnknown_QueryServiceExec(ptr ptr ptr long long long ptr) -485 stub -noname MapWin32ErrorToSTG +485 stdcall -noname MapWin32ErrorToSTG(long) 486 stub -noname ModeToCreateFileFlags 487 stdcall -ordinal SHLoadIndirectString(wstr ptr long ptr) 488 stub -noname SHConvertGraphicsFile diff --git a/dll/win32/shlwapi/utils.cpp b/dll/win32/shlwapi/utils.cpp index a380bec3168..414b830f5d2 100644 --- a/dll/win32/shlwapi/utils.cpp +++ b/dll/win32/shlwapi/utils.cpp @@ -219,6 +219,29 @@ PathUnExpandEnvStringsForUserW( return FALSE; } +/************************************************************************* + * MapWin32ErrorToSTG [SHLWAPI.485] + * + * https://undoc.airesoft.co.uk/shlwapi.dll/MapWin32ErrorToSTG.php + */ +EXTERN_C HRESULT WINAPI +MapWin32ErrorToSTG(_In_ HRESULT hr) +{ + switch (hr) + { + case HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED): + return STG_E_ACCESSDENIED; + case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): + case HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND): + return STG_E_FILENOTFOUND; + case HRESULT_FROM_WIN32(ERROR_FILE_EXISTS): + case HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS): + return STG_E_FILEALREADYEXISTS; + default: + return hr; + } +} + static BOOL CharLowerNoDBCSAWorker(PSTR lpString, INT cchMax, BOOL bUppercase) { CHAR szBuff[MAX_PATH]; diff --git a/modules/rostests/apitests/shlwapi/CMakeLists.txt b/modules/rostests/apitests/shlwapi/CMakeLists.txt index 2359bcd4323..d64025c193c 100644 --- a/modules/rostests/apitests/shlwapi/CMakeLists.txt +++ b/modules/rostests/apitests/shlwapi/CMakeLists.txt @@ -11,6 +11,7 @@ list(APPEND SOURCE IShellFolderHelpers.cpp IsQSForward.cpp IStreamPidl.cpp + MapWin32ErrorToSTG.c NextPath.c PathFileExistsDefExtAndAttributesW.c PathFindOnPath.c diff --git a/modules/rostests/apitests/shlwapi/MapWin32ErrorToSTG.c b/modules/rostests/apitests/shlwapi/MapWin32ErrorToSTG.c new file mode 100644 index 00000000000..293266df424 --- /dev/null +++ b/modules/rostests/apitests/shlwapi/MapWin32ErrorToSTG.c @@ -0,0 +1,45 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: Tests for MapWin32ErrorToSTG + * COPYRIGHT: Copyright 2026 Katayama Hirofumi MZ + */ + +#include +#include + +typedef HRESULT (WINAPI *FN_MapWin32ErrorToSTG)(HRESULT); +static FN_MapWin32ErrorToSTG s_fnMapWin32ErrorToSTG = NULL; + +START_TEST(MapWin32ErrorToSTG) +{ + HRESULT hr; + HINSTANCE hSHLWAPI; + + hSHLWAPI = GetModuleHandleA("shlwapi"); + s_fnMapWin32ErrorToSTG = (FN_MapWin32ErrorToSTG) + GetProcAddress(hSHLWAPI, MAKEINTRESOURCEA(485)); + if (!s_fnMapWin32ErrorToSTG) + { + skip("MapWin32ErrorToSTG not found\n"); + return; + } + + hr = s_fnMapWin32ErrorToSTG(HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)); + ok_long(hr, STG_E_ACCESSDENIED); + + hr = s_fnMapWin32ErrorToSTG(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); + ok_long(hr, STG_E_FILENOTFOUND); + + hr = s_fnMapWin32ErrorToSTG(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)); + ok_long(hr, STG_E_FILENOTFOUND); + + hr = s_fnMapWin32ErrorToSTG(HRESULT_FROM_WIN32(ERROR_FILE_EXISTS)); + ok_long(hr, STG_E_FILEALREADYEXISTS); + + hr = s_fnMapWin32ErrorToSTG(HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)); + ok_long(hr, STG_E_FILEALREADYEXISTS); + + hr = s_fnMapWin32ErrorToSTG(HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)); + ok_long(hr, HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)); +} diff --git a/modules/rostests/apitests/shlwapi/testlist.c b/modules/rostests/apitests/shlwapi/testlist.c index 39a97ce9d85..21892624223 100644 --- a/modules/rostests/apitests/shlwapi/testlist.c +++ b/modules/rostests/apitests/shlwapi/testlist.c @@ -9,6 +9,7 @@ extern void func_PathFindOnPath(void); extern void func_IShellFolderHelpers(void); extern void func_IsQSForward(void); extern void func_IStreamPidl(void); +extern void func_MapWin32ErrorToSTG(void); extern void func_NextPath(void); extern void func_PathIsUNC(void); extern void func_PathIsUNCServer(void); @@ -37,6 +38,7 @@ const struct test winetest_testlist[] = { "IShellFolderHelpers", func_IShellFolderHelpers }, { "IsQSForward", func_IsQSForward }, { "IStreamPidl", func_IStreamPidl }, + { "MapWin32ErrorToSTG", func_MapWin32ErrorToSTG }, { "NextPath", func_NextPath }, { "PathIsUNC", func_PathIsUNC }, { "PathIsUNCServer", func_PathIsUNCServer }, diff --git a/sdk/include/reactos/shlwapi_undoc.h b/sdk/include/reactos/shlwapi_undoc.h index 6bff319fa3f..a06d49b9f65 100644 --- a/sdk/include/reactos/shlwapi_undoc.h +++ b/sdk/include/reactos/shlwapi_undoc.h @@ -513,6 +513,8 @@ SHDialogBox( _In_opt_ SHDIALOGPROC fn, _In_opt_ PVOID pThis); +HRESULT WINAPI MapWin32ErrorToSTG(_In_ HRESULT hr); + PSTR WINAPI CharLowerNoDBCSA(_Inout_ PSTR lpString); PWSTR WINAPI CharLowerNoDBCSW(_Inout_ PWSTR lpString); PSTR WINAPI CharUpperNoDBCSA(_Inout_ PSTR lpString);