ReactOS 0.4.15-dev-5669-g09dde2c
main.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Applications Manager Command-Line Launcher (rapps.com)
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Allow explorer / cmd to wait for rapps.exe when passing commandline arguments
5 * COPYRIGHT: Copyright 2020 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include <windef.h>
9#include <winbase.h>
10#include <strsafe.h>
11
13{
14 DWORD dwExit;
15 STARTUPINFOW si = { sizeof(si) };
16 PROCESS_INFORMATION pi = { 0 };
17
18 SetLastError(0);
19 if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
20 {
21 fprintf(stderr, "Unable to create rapps.exe process...\n");
22 return -1;
23 }
24 CloseHandle(pi.hThread);
26 GetExitCodeProcess(pi.hProcess, &dwExit);
27 CloseHandle(pi.hProcess);
28 return (int)dwExit;
29}
30
31int wmain(int argc, wchar_t* argv[])
32{
33 int iRet;
34 int n;
35 size_t arglen;
36 WCHAR RappsExe[MAX_PATH] = { 0 };
37 wchar_t* cmdline;
38
39 GetModuleFileNameW(NULL, RappsExe, ARRAYSIZE(RappsExe));
40 arglen = wcslen(RappsExe);
41 if (arglen > 4 && !wcsicmp(RappsExe + arglen - 4, L".com"))
42 {
43 wcscpy(RappsExe + arglen - 4, L".exe");
44 }
45 else
46 {
47 fprintf(stderr, "Unable to build rapps.exe path...\n");
48 return -1;
49 }
50
51 arglen += (1 + 2); // NULL terminator + 2 quotes
52
53 for (n = 1; n < argc; ++n)
54 {
55 arglen += wcslen(argv[n]);
56 arglen += 3; // Surrounding quotes + space
57 }
58
60 if (cmdline)
61 {
62 wchar_t* ptr = cmdline;
63 size_t cchRemaining = arglen;
64
65 StringCchPrintfExW(ptr, cchRemaining, &ptr, &cchRemaining, 0, L"\"%s\"", RappsExe);
66
67 for (n = 1; n < argc; ++n)
68 {
69 StringCchPrintfExW(ptr, cchRemaining, &ptr, &cchRemaining, 0, L" \"%s\"", argv[n]);
70 }
71 }
72
73 iRet = run_rapps(cmdline);
74 if (cmdline)
76 return iRet;
77}
static int argc
Definition: ServiceArgs.c:12
int run_rapps(LPWSTR cmdline)
Definition: main.c:12
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define wcsicmp
Definition: compat.h:15
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4593
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble n
Definition: glext.h:7729
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static PVOID ptr
Definition: dispmode.c:27
static refpint_t pi[]
Definition: server.c:96
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
int wmain()
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
TCHAR * cmdline
Definition: stretchblt.cpp:32
STRSAFEAPI StringCchPrintfExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:585
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184