summaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/app2util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/app2util.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/app2util.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/app2util.cpp b/src/libs/dutil/WixToolset.DUtil/app2util.cpp
new file mode 100644
index 00000000..d2e21e39
--- /dev/null
+++ b/src/libs/dutil/WixToolset.DUtil/app2util.cpp
@@ -0,0 +1,60 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#include "precomp.h"
4
5// Exit macros
6#define AppExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
7#define AppExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
8#define AppExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
9#define AppExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
10#define AppExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
11#define AppExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_APPUTIL, x, e, s, __VA_ARGS__)
12#define AppExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
13#define AppExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__)
14#define AppExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__)
15#define AppExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__)
16#define AppExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__)
17#define AppExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_APPUTIL, e, x, s, __VA_ARGS__)
18#define AppExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_APPUTIL, g, x, s, __VA_ARGS__)
19
20DAPI_(void) AppFreeCommandLineArgs(
21 __in LPWSTR* argv
22 )
23{
24 // The "ignored" hack in AppParseCommandLine requires an adjustment.
25 LPWSTR* argvOriginal = argv - 1;
26 ::LocalFree(argvOriginal);
27}
28
29DAPI_(HRESULT) AppParseCommandLine(
30 __in LPCWSTR wzCommandLine,
31 __in int* pArgc,
32 __in LPWSTR** pArgv
33 )
34{
35 HRESULT hr = S_OK;
36 LPWSTR sczCommandLine = NULL;
37 LPWSTR* argv = NULL;
38 int argc = 0;
39
40 // CommandLineToArgvW tries to treat the first argument as the path to the process,
41 // which fails pretty miserably if your first argument is something like
42 // FOO="C:\Program Files\My Company". So give it something harmless to play with.
43 hr = StrAllocConcat(&sczCommandLine, L"ignored ", 0);
44 AppExitOnFailure(hr, "Failed to initialize command line.");
45
46 hr = StrAllocConcat(&sczCommandLine, wzCommandLine, 0);
47 AppExitOnFailure(hr, "Failed to copy command line.");
48
49 argv = ::CommandLineToArgvW(sczCommandLine, &argc);
50 AppExitOnNullWithLastError(argv, hr, "Failed to parse command line.");
51
52 // Skip "ignored" argument/hack.
53 *pArgv = argv + 1;
54 *pArgc = argc - 1;
55
56LExit:
57 ReleaseStr(sczCommandLine);
58
59 return hr;
60}