diff options
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/svcutil.cpp')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/svcutil.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/svcutil.cpp b/src/libs/dutil/WixToolset.DUtil/svcutil.cpp new file mode 100644 index 00000000..1a39bfee --- /dev/null +++ b/src/libs/dutil/WixToolset.DUtil/svcutil.cpp | |||
| @@ -0,0 +1,59 @@ | |||
| 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 | |||
| 6 | // Exit macros | ||
| 7 | #define SvcExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
| 8 | #define SvcExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
| 9 | #define SvcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
| 10 | #define SvcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define SvcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define SvcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SVCUTIL, x, s, __VA_ARGS__) | ||
| 13 | #define SvcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SVCUTIL, p, x, e, s, __VA_ARGS__) | ||
| 14 | #define SvcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, p, x, s, __VA_ARGS__) | ||
| 15 | #define SvcExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SVCUTIL, p, x, e, s, __VA_ARGS__) | ||
| 16 | #define SvcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SVCUTIL, p, x, s, __VA_ARGS__) | ||
| 17 | #define SvcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SVCUTIL, e, x, s, __VA_ARGS__) | ||
| 18 | #define SvcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SVCUTIL, g, x, s, __VA_ARGS__) | ||
| 19 | |||
| 20 | /******************************************************************** | ||
| 21 | SvcQueryConfig - queries the configuration of a service | ||
| 22 | |||
| 23 | ********************************************************************/ | ||
| 24 | extern "C" HRESULT DAPI SvcQueryConfig( | ||
| 25 | __in SC_HANDLE sch, | ||
| 26 | __out QUERY_SERVICE_CONFIGW** ppConfig | ||
| 27 | ) | ||
| 28 | { | ||
| 29 | HRESULT hr = S_OK; | ||
| 30 | QUERY_SERVICE_CONFIGW* pConfig = NULL; | ||
| 31 | DWORD cbConfig = 0; | ||
| 32 | |||
| 33 | if (!::QueryServiceConfigW(sch, NULL, 0, &cbConfig)) | ||
| 34 | { | ||
| 35 | DWORD er = ::GetLastError(); | ||
| 36 | if (ERROR_INSUFFICIENT_BUFFER == er) | ||
| 37 | { | ||
| 38 | pConfig = static_cast<QUERY_SERVICE_CONFIGW*>(MemAlloc(cbConfig, TRUE)); | ||
| 39 | SvcExitOnNull(pConfig, hr, E_OUTOFMEMORY, "Failed to allocate memory to get configuration."); | ||
| 40 | |||
| 41 | if (!::QueryServiceConfigW(sch, pConfig, cbConfig, &cbConfig)) | ||
| 42 | { | ||
| 43 | SvcExitWithLastError(hr, "Failed to read service configuration."); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | else | ||
| 47 | { | ||
| 48 | SvcExitOnWin32Error(er, hr, "Failed to query service configuration."); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | *ppConfig = pConfig; | ||
| 53 | pConfig = NULL; | ||
| 54 | |||
| 55 | LExit: | ||
| 56 | ReleaseMem(pConfig); | ||
| 57 | |||
| 58 | return hr; | ||
| 59 | } | ||
