From ce2c1f6321f3e59da86970f545ec497ebf0e54cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 5 Nov 2020 19:55:33 +0100 Subject: [PATCH] [RAPPS.COM] Use HeapAlloc/Free instead of the deprecated LocalAlloc/Free. And fix my build. --- base/applications/rapps_com/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/base/applications/rapps_com/main.c b/base/applications/rapps_com/main.c index fdb583f053d..d5f7c01ff0f 100644 --- a/base/applications/rapps_com/main.c +++ b/base/applications/rapps_com/main.c @@ -9,11 +9,12 @@ #include #include - int run_rapps(LPWSTR cmdline) { + DWORD dwExit; STARTUPINFOW si = { sizeof(si) }; PROCESS_INFORMATION pi = { 0 }; + SetLastError(0); if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { @@ -22,18 +23,21 @@ int run_rapps(LPWSTR cmdline) } CloseHandle(pi.hThread); WaitForSingleObject(pi.hProcess, INFINITE); - DWORD dwExit; GetExitCodeProcess(pi.hProcess, &dwExit); CloseHandle(pi.hProcess); - return dwExit; + return (int)dwExit; } int wmain(int argc, wchar_t* argv[]) { + int iRet; + int n; + size_t arglen; WCHAR RappsExe[MAX_PATH] = { 0 }; + wchar_t* cmdline; GetModuleFileNameW(NULL, RappsExe, ARRAYSIZE(RappsExe)); - size_t arglen = wcslen(RappsExe); + arglen = wcslen(RappsExe); if (arglen > 4 && !wcsicmp(RappsExe + arglen - 4, L".com")) { wcscpy(RappsExe + arglen - 4, L".exe"); @@ -41,18 +45,18 @@ int wmain(int argc, wchar_t* argv[]) else { fprintf(stderr, "Unable to build rapps.exe path...\n"); - return - 1; + return -1; } - arglen += (1 + 2); // nullterminator + 2 quotes + arglen += (1 + 2); // NULL terminator + 2 quotes - for (int n = 1; n < argc; ++n) + for (n = 1; n < argc; ++n) { arglen += wcslen(argv[n]); arglen += 3; // Surrounding quotes + space } - wchar_t* cmdline = LocalAlloc(LMEM_ZEROINIT, arglen * sizeof(WCHAR)); + cmdline = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, arglen * sizeof(WCHAR)); if (cmdline) { wchar_t* ptr = cmdline; @@ -60,14 +64,14 @@ int wmain(int argc, wchar_t* argv[]) StringCchPrintfExW(ptr, cchRemaining, &ptr, &cchRemaining, 0, L"\"%s\"", RappsExe); - for (int n = 1; n < argc; ++n) + for (n = 1; n < argc; ++n) { StringCchPrintfExW(ptr, cchRemaining, &ptr, &cchRemaining, 0, L" \"%s\"", argv[n]); } } - int iRet = run_rapps(cmdline); + iRet = run_rapps(cmdline); if (cmdline) - LocalFree(cmdline); + HeapFree(GetProcessHeap(), 0, cmdline); return iRet; }