[RAPPS.COM] Use HeapAlloc/Free instead of the deprecated LocalAlloc/Free.

And fix my build.
This commit is contained in:
Hermès Bélusca-Maïto 2020-11-05 19:55:33 +01:00
parent ce55fef1e5
commit ce2c1f6321
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -9,11 +9,12 @@
#include <winbase.h>
#include <strsafe.h>
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");
@ -44,15 +48,15 @@ int wmain(int argc, wchar_t* argv[])
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;
}