-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
231 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[assembly: SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = "Mostly useless")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
namespace SheetReader.Wpf.Utilities | ||
{ | ||
public sealed class EventProvider : IDisposable | ||
{ | ||
// use WpfTraceSpy to read this https://github.com/smourier/TraceSpy ("ETW messages support") | ||
public static EventProvider Default { get; } = new(new Guid("964d4572-adb9-4f3a-8170-fcbecec27467")); | ||
|
||
private long _handle; | ||
public Guid Id { get; } | ||
|
||
public EventProvider(Guid id) | ||
{ | ||
Id = id; | ||
var hr = EventRegister(id, IntPtr.Zero, IntPtr.Zero, out _handle); | ||
if (hr != 0) | ||
throw new Win32Exception(hr); | ||
} | ||
|
||
public bool WriteMessageEvent(string text, byte level = 0, long keywords = 0) => EventWriteString(_handle, level, keywords, text) == 0; | ||
|
||
public void Dispose() | ||
{ | ||
var handle = Interlocked.Exchange(ref _handle, 0); | ||
if (handle != 0) | ||
{ | ||
_ = EventUnregister(handle); | ||
} | ||
} | ||
|
||
[DllImport("advapi32")] | ||
private static extern int EventRegister([MarshalAs(UnmanagedType.LPStruct)] Guid ProviderId, IntPtr EnableCallback, IntPtr CallbackContext, out long RegHandle); | ||
|
||
[DllImport("advapi32")] | ||
private static extern int EventUnregister(long RegHandle); | ||
|
||
[DllImport("advapi32")] | ||
private static extern int EventWriteString(long RegHandle, byte Level, long Keyword, [MarshalAs(UnmanagedType.LPWStr)] string String); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.