| 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 GuidExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 8 | #define GuidExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 9 | #define GuidExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 10 | #define GuidExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 11 | #define GuidExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 12 | #define GuidExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_GUIDUTIL, x, e, s, __VA_ARGS__) |
| 13 | #define GuidExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 14 | #define GuidExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__) |
| 15 | #define GuidExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__) |
| 16 | #define GuidExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__) |
| 17 | #define GuidExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__) |
| 18 | #define GuidExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_GUIDUTIL, e, x, s, __VA_ARGS__) |
| 19 | #define GuidExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_GUIDUTIL, g, x, s, __VA_ARGS__) |
| 20 | |
| 21 | extern "C" HRESULT DAPI GuidFixedCreate( |
| 22 | _Out_z_cap_c_(GUID_STRING_LENGTH) WCHAR* wzGuid |
| 23 | ) |
| 24 | { |
| 25 | HRESULT hr = S_OK; |
| 26 | UUID guid = { }; |
| 27 | |
| 28 | hr = HRESULT_FROM_RPC(::UuidCreate(&guid)); |
| 29 | GuidExitOnFailure(hr, "UuidCreate failed."); |
| 30 | |
| 31 | if (!::StringFromGUID2(guid, wzGuid, GUID_STRING_LENGTH)) |
| 32 | { |
| 33 | GuidExitWithRootFailure(hr, E_OUTOFMEMORY, "Failed to convert guid into string."); |
| 34 | } |
| 35 | |
| 36 | LExit: |
| 37 | return hr; |
| 38 | } |
| 39 | |
| 40 | extern "C" HRESULT DAPI GuidCreate( |
| 41 | __deref_out_z LPWSTR* psczGuid |
| 42 | ) |
| 43 | { |
| 44 | HRESULT hr = S_OK; |
| 45 | |
| 46 | hr = StrAlloc(psczGuid, GUID_STRING_LENGTH); |
| 47 | GuidExitOnFailure(hr, "Failed to allocate space for guid"); |
| 48 | |
| 49 | hr = GuidFixedCreate(*psczGuid); |
| 50 | GuidExitOnFailure(hr, "Failed to create new guid."); |
| 51 | |
| 52 | LExit: |
| 53 | return hr; |
| 54 | } |