mirror of
https://github.com/reactos/reactos.git
synced 2025-07-27 07:41:51 +00:00
[RAPPS.COM] Use HeapAlloc/Free instead of the deprecated LocalAlloc/Free.
And fix my build.
This commit is contained in:
parent
ce55fef1e5
commit
ce2c1f6321
1 changed files with 15 additions and 11 deletions
|
@ -9,11 +9,12 @@
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
|
||||||
|
|
||||||
int run_rapps(LPWSTR cmdline)
|
int run_rapps(LPWSTR cmdline)
|
||||||
{
|
{
|
||||||
|
DWORD dwExit;
|
||||||
STARTUPINFOW si = { sizeof(si) };
|
STARTUPINFOW si = { sizeof(si) };
|
||||||
PROCESS_INFORMATION pi = { 0 };
|
PROCESS_INFORMATION pi = { 0 };
|
||||||
|
|
||||||
SetLastError(0);
|
SetLastError(0);
|
||||||
if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
|
if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
|
||||||
{
|
{
|
||||||
|
@ -22,18 +23,21 @@ int run_rapps(LPWSTR cmdline)
|
||||||
}
|
}
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
DWORD dwExit;
|
|
||||||
GetExitCodeProcess(pi.hProcess, &dwExit);
|
GetExitCodeProcess(pi.hProcess, &dwExit);
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
return dwExit;
|
return (int)dwExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wmain(int argc, wchar_t* argv[])
|
int wmain(int argc, wchar_t* argv[])
|
||||||
{
|
{
|
||||||
|
int iRet;
|
||||||
|
int n;
|
||||||
|
size_t arglen;
|
||||||
WCHAR RappsExe[MAX_PATH] = { 0 };
|
WCHAR RappsExe[MAX_PATH] = { 0 };
|
||||||
|
wchar_t* cmdline;
|
||||||
|
|
||||||
GetModuleFileNameW(NULL, RappsExe, ARRAYSIZE(RappsExe));
|
GetModuleFileNameW(NULL, RappsExe, ARRAYSIZE(RappsExe));
|
||||||
size_t arglen = wcslen(RappsExe);
|
arglen = wcslen(RappsExe);
|
||||||
if (arglen > 4 && !wcsicmp(RappsExe + arglen - 4, L".com"))
|
if (arglen > 4 && !wcsicmp(RappsExe + arglen - 4, L".com"))
|
||||||
{
|
{
|
||||||
wcscpy(RappsExe + arglen - 4, L".exe");
|
wcscpy(RappsExe + arglen - 4, L".exe");
|
||||||
|
@ -41,18 +45,18 @@ int wmain(int argc, wchar_t* argv[])
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to build rapps.exe path...\n");
|
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 += wcslen(argv[n]);
|
||||||
arglen += 3; // Surrounding quotes + space
|
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)
|
if (cmdline)
|
||||||
{
|
{
|
||||||
wchar_t* ptr = 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);
|
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]);
|
StringCchPrintfExW(ptr, cchRemaining, &ptr, &cchRemaining, 0, L" \"%s\"", argv[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int iRet = run_rapps(cmdline);
|
iRet = run_rapps(cmdline);
|
||||||
if (cmdline)
|
if (cmdline)
|
||||||
LocalFree(cmdline);
|
HeapFree(GetProcessHeap(), 0, cmdline);
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue