mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Replace DllImport with LibraryImport in SMA - 7 (#18594)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#nullable enable
|
||||
|
||||
#if !UNIX
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
internal static partial class Windows
|
||||
{
|
||||
internal enum ActivityControl : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the ActivityId from thread local storage.
|
||||
/// </summary>
|
||||
Get = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Sets the ActivityId in the thread local storage.
|
||||
/// </summary>
|
||||
Set = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new activity id.
|
||||
/// </summary>
|
||||
Create = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Sets the activity id in thread local storage and returns the previous value.
|
||||
/// </summary>
|
||||
GetSet = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new activity id, sets thread local storage, and returns the previous value.
|
||||
/// </summary>
|
||||
CreateSet = 5
|
||||
}
|
||||
|
||||
[LibraryImport("api-ms-win-eventing-provider-l1-1-0.dll")]
|
||||
internal static unsafe partial int EventActivityIdControl(ActivityControl controlCode, Guid* activityId);
|
||||
|
||||
internal static unsafe int GetEventActivityIdControl(ref Guid activityId)
|
||||
{
|
||||
fixed (Guid* guidPtr = &activityId)
|
||||
{
|
||||
return EventActivityIdControl(ActivityControl.Get, guidPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -300,7 +300,7 @@ namespace System.Management.Automation.Tracing
|
||||
public static Guid GetActivityId()
|
||||
{
|
||||
Guid activityId = Guid.Empty;
|
||||
uint hresult = UnsafeNativeMethods.EventActivityIdControl(UnsafeNativeMethods.ActivityControlCode.Get, ref activityId);
|
||||
Interop.Windows.GetEventActivityIdControl(ref activityId);
|
||||
return activityId;
|
||||
}
|
||||
|
||||
@@ -496,46 +496,6 @@ namespace System.Management.Automation.Tracing
|
||||
|
||||
return currentProvider;
|
||||
}
|
||||
|
||||
private static class UnsafeNativeMethods
|
||||
{
|
||||
internal enum ActivityControlCode : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the ActivityId from thread local storage.
|
||||
/// </summary>
|
||||
Get = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Sets the ActivityId in the thread local storage.
|
||||
/// </summary>
|
||||
Set = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new activity id.
|
||||
/// </summary>
|
||||
Create = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Sets the activity id in thread local storage and returns the previous value.
|
||||
/// </summary>
|
||||
GetSet = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new activity id, sets thread local storage, and returns the previous value.
|
||||
/// </summary>
|
||||
CreateSet = 5
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides interop access to creating, querying and setting the current activity identifier.
|
||||
/// </summary>
|
||||
/// <param name="controlCode">The <see cref="ActivityControlCode"/> indicating the type of operation to perform.</param>
|
||||
/// <param name="activityId">The activity id to set or retrieve.</param>
|
||||
/// <returns>Zero on success.</returns>
|
||||
[DllImport(PinvokeDllNames.EventActivityIdControlDllName, ExactSpelling = true, EntryPoint = "EventActivityIdControl", CharSet = CharSet.Unicode)]
|
||||
internal static extern unsafe uint EventActivityIdControl([In] ActivityControlCode controlCode, [In][Out] ref Guid activityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user