From 0135440d50089f56cb71f94aae4a313e488676d7 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 22 Nov 2025 16:53:33 +0100 Subject: [PATCH] [NETSH] Implement MakeString and FreeString Used by the 'winsock show catalog' command. --- base/applications/network/netsh/netsh.c | 47 ++++++++++++++++++++++ base/applications/network/netsh/netsh.spec | 4 +- sdk/include/reactos/netsh_undoc.h | 12 ++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/base/applications/network/netsh/netsh.c b/base/applications/network/netsh/netsh.c index 6f915dd3d07..fed5e450ad3 100644 --- a/base/applications/network/netsh/netsh.c +++ b/base/applications/network/netsh/netsh.c @@ -273,6 +273,15 @@ FreeQuotedString( HeapFree(GetProcessHeap(), 0, pszQuotedString); } +VOID +WINAPI +FreeString( + _In_ LPWSTR pszString) +{ + DPRINT("FreeString(%S)\n", pszString); + LocalFree(pszString); +} + LPWSTR WINAPI MakeQuotedString( @@ -291,6 +300,44 @@ MakeQuotedString( return pszQuotedString; } +LPWSTR +CDECL +MakeString( + _In_ HANDLE hModule, + _In_ DWORD dwMsgId, + ...) +{ + LPWSTR pszInBuffer, pszOutBuffer = NULL; + DWORD dwLength; + va_list ap; + + DPRINT("MakeString(%p %lu ...)\n", hModule, dwMsgId); + + va_start(ap, dwMsgId); + + pszInBuffer = HeapAlloc(GetProcessHeap(), 0, HUGE_BUFFER_SIZE * sizeof(WCHAR)); + if (pszInBuffer == NULL) + return NULL; + + dwLength = LoadStringW(hModule, dwMsgId, pszInBuffer, HUGE_BUFFER_SIZE); + if (dwLength > 0) + goto done; + + FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING, + pszInBuffer, + 0, + 0, + (LPWSTR)&pszOutBuffer, + 0, + &ap); + +done: + if (pszInBuffer) + HeapFree(GetProcessHeap(), 0, pszInBuffer); + + return pszOutBuffer; +} + DWORD WINAPI MatchEnumTag( diff --git a/base/applications/network/netsh/netsh.spec b/base/applications/network/netsh/netsh.spec index 282ce19d7a6..f99aa59d9e7 100644 --- a/base/applications/network/netsh/netsh.spec +++ b/base/applications/network/netsh/netsh.spec @@ -3,13 +3,13 @@ @ stub DisplayMessageM @ stub DisplayMessageToConsole @ stdcall FreeQuotedString(wstr) -@ stub FreeString +@ stdcall FreeString(wstr) @ stub GenericMonitor @ stub GetEnumString @ stub GetHostMachineInfo @ stub InitializeConsole @ stdcall MakeQuotedString(wstr) -@ stub MakeString +@ varargs MakeString(ptr long) @ stub MatchCmdLine @ stdcall MatchEnumTag(ptr wstr long ptr ptr) @ stub MatchTagsInCmdLine diff --git a/sdk/include/reactos/netsh_undoc.h b/sdk/include/reactos/netsh_undoc.h index 7736b64d113..a2cf671adb3 100644 --- a/sdk/include/reactos/netsh_undoc.h +++ b/sdk/include/reactos/netsh_undoc.h @@ -6,11 +6,23 @@ WINAPI FreeQuotedString( _In_ LPWSTR pszQuotedString); +VOID +WINAPI +FreeString( + _In_ LPWSTR pszString); + LPWSTR WINAPI MakeQuotedString( _In_ LPWSTR pszString); +LPWSTR +CDECL +MakeString( + _In_ HANDLE hModule, + _In_ DWORD dwMsgId, + ...); + DWORD WINAPI NsGetFriendlyNameFromIfName(