1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 using System
.Runtime
.InteropServices
;
7 #if ES_BUILD_STANDALONE
8 using Microsoft
.Diagnostics
.Tracing
;
10 using System
.Diagnostics
.Tracing
;
13 internal static partial class Interop
15 internal static partial class Advapi32
18 /// Call the ETW native API EventWriteTransfer and checks for invalid argument error.
19 /// The implementation of EventWriteTransfer on some older OSes (Windows 2008) does not accept null relatedActivityId.
20 /// So, for these cases we will retry the call with an empty Guid.
22 internal static unsafe int EventWriteTransfer(
23 long registrationHandle
,
24 in EventDescriptor eventDescriptor
,
26 Guid
* relatedActivityId
,
28 EventProvider
.EventData
* userData
)
30 int HResult
= EventWriteTransfer_PInvoke(registrationHandle
, in eventDescriptor
, activityId
, relatedActivityId
, userDataCount
, userData
);
31 if (HResult
== Errors
.ERROR_INVALID_PARAMETER
&& relatedActivityId
== null)
33 Guid emptyGuid
= Guid
.Empty
;
34 HResult
= EventWriteTransfer_PInvoke(registrationHandle
, in eventDescriptor
, activityId
, &emptyGuid
, userDataCount
, userData
);
40 [DllImport(Interop
.Libraries
.Advapi32
, ExactSpelling
= true, EntryPoint
= "EventWriteTransfer")]
41 private static extern unsafe int EventWriteTransfer_PInvoke(
42 long registrationHandle
,
43 in EventDescriptor eventDescriptor
,
45 Guid
* relatedActivityId
,
47 EventProvider
.EventData
* userData
);