From 9789f02b1ba690e26cfee9b1bb3f792b0e1b6919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Fri, 14 Jan 2022 20:08:40 +0100 Subject: [PATCH] feat: update samples to use UnmanagedCallersOnly entrypoint --- Samples/InterceptNameChanger/DllMain.cs | 17 ++++--- .../InterceptNameChanger.csproj | 44 +---------------- Samples/SimpleChat/DllMain.cs | 13 +++-- Samples/SimpleChat/SimpleChat.csproj | 43 +---------------- Samples/WalkCommands/DllMain.cs | 2 +- Samples/WalkCommands/WalkCommands.csproj | 47 ++----------------- 6 files changed, 22 insertions(+), 144 deletions(-) diff --git a/Samples/InterceptNameChanger/DllMain.cs b/Samples/InterceptNameChanger/DllMain.cs index e8b2bd9..48a5c08 100644 --- a/Samples/InterceptNameChanger/DllMain.cs +++ b/Samples/InterceptNameChanger/DllMain.cs @@ -23,22 +23,21 @@ namespace InterceptNameChanger /// /// The main entrypoint method of the dll. /// - /// The handle of the module. - [DllExport] - public static void Main(IntPtr handle) + [UnmanagedCallersOnly(EntryPoint = "Main")] + public static void Main() { AllocConsole(); Console.WriteLine("Hello from InterceptNameChanger DllMain entry point."); new Thread(() => { - try - { - new NameChanger().RunAsync().GetAwaiter().GetResult(); + try + { + new NameChanger().RunAsync().GetAwaiter().GetResult(); } - catch (Exception e) - { - Console.WriteLine(e.ToString()); + catch (Exception e) + { + Console.WriteLine(e.ToString()); } }).Start(); } diff --git a/Samples/InterceptNameChanger/InterceptNameChanger.csproj b/Samples/InterceptNameChanger/InterceptNameChanger.csproj index fd66e66..cf0aef0 100644 --- a/Samples/InterceptNameChanger/InterceptNameChanger.csproj +++ b/Samples/InterceptNameChanger/InterceptNameChanger.csproj @@ -3,35 +3,13 @@ net6.0 enable 10 - - - 89E4EE92-5848-4390-A6A7-34972FE923F5 - DllExport.dll - InterceptNameChanger - true - x86 - 7 - false - false - false - false - 30000 - 2 - 0 - 0 - 0 - false + true all runtime; build; native; contentfiles; analyzers; buildtransitive - - 1.7.4 - false - 1 - all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -44,24 +22,4 @@ - - - - - - - - - - - - $(SolutionDir)packages\DllExport.1.7.4\gcache\$(DllExportMetaXBase)\$(DllExportNamespace)\$(DllExportMetaLibName) - False - False - - - - - - \ No newline at end of file diff --git a/Samples/SimpleChat/DllMain.cs b/Samples/SimpleChat/DllMain.cs index 96a1381..b263595 100644 --- a/Samples/SimpleChat/DllMain.cs +++ b/Samples/SimpleChat/DllMain.cs @@ -4,15 +4,15 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Runtime.InteropServices; - +using System.Runtime.InteropServices; + namespace SimpleChat; /// /// The main entrypoint class of the dll. /// public class DllMain -{ +{ [DllImport("kernel32")] #pragma warning disable SA1600 public static extern bool AllocConsole(); @@ -21,10 +21,9 @@ public class DllMain /// /// The main entrypoint method of the dll. /// - /// The handle of the module. - [DllExport] - public static void Main(IntPtr handle) - { + [UnmanagedCallersOnly(EntryPoint = "Main")] + public static void Main() + { AllocConsole(); Console.WriteLine("Hello from SimpleChat DllMain entry point."); diff --git a/Samples/SimpleChat/SimpleChat.csproj b/Samples/SimpleChat/SimpleChat.csproj index 9939c7c..2907d99 100644 --- a/Samples/SimpleChat/SimpleChat.csproj +++ b/Samples/SimpleChat/SimpleChat.csproj @@ -4,34 +4,13 @@ enable enable 10 - - - 89E4EE92-5848-4390-A6A7-34972FE923F5 - DllExport.dll - SimpleChat - true - x86 - 7 - false - false - false - false - 30000 - 2 - 0 - 0 - 0 + true all runtime; build; native; contentfiles; analyzers; buildtransitive - - 1.7.4 - false - 1 - all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -44,24 +23,4 @@ - - - - - - - - - - - - $(SolutionDir)packages\DllExport.1.7.4\gcache\$(DllExportMetaXBase)\$(DllExportNamespace)\$(DllExportMetaLibName) - False - False - - - - - - \ No newline at end of file diff --git a/Samples/WalkCommands/DllMain.cs b/Samples/WalkCommands/DllMain.cs index b732493..56e71de 100644 --- a/Samples/WalkCommands/DllMain.cs +++ b/Samples/WalkCommands/DllMain.cs @@ -21,7 +21,7 @@ public class DllMain /// /// Represents the dll entrypoint method. /// - [DllExport] + [UnmanagedCallersOnly(EntryPoint = "Main")] public static void Main() { AllocConsole(); diff --git a/Samples/WalkCommands/WalkCommands.csproj b/Samples/WalkCommands/WalkCommands.csproj index 797ab3d..bdffb9c 100644 --- a/Samples/WalkCommands/WalkCommands.csproj +++ b/Samples/WalkCommands/WalkCommands.csproj @@ -6,23 +6,8 @@ WalkCommands WalkCommands 10 - - - 9C088A1D-54DE-4A9B-9C1B-DBC5BD5F5299 - DllExport.dll - WalkCommands - true - x86 - 7 - false - false - false - false - 30000 - 2 - 0 - 0 - 0 + true + true @@ -30,11 +15,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - 1.7.4 - false - 1 - 6.6.0 all @@ -49,28 +29,11 @@ 6.0.0 + + 7.1.0 + - - - - - - - - - - - - $(SolutionDir)packages\DllExport.1.7.4\gcache\$(DllExportMetaXBase)\$(DllExportNamespace)\$(DllExportMetaLibName) - False - False - - - - - - \ No newline at end of file -- 2.48.1