From 853f88956014a6fdf76359867c969acb9bce18e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 25 Nov 2025 01:18:13 +0000 Subject: [PATCH] Add support to process pointer parameters - Now encodes pointer parameters with valid C++ names. - Add method with pointer parameter to test app. --- .../Utility/NativeMethodsCrc.cs | 15 ++++++++++----- .../NativeMethodGeneration.cs | 5 ++++- .../StubsGenerationTestNFApp.nfproj | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/MetadataProcessor.Shared/Utility/NativeMethodsCrc.cs b/MetadataProcessor.Shared/Utility/NativeMethodsCrc.cs index 1b6a7b0c..dcb50a83 100644 --- a/MetadataProcessor.Shared/Utility/NativeMethodsCrc.cs +++ b/MetadataProcessor.Shared/Utility/NativeMethodsCrc.cs @@ -191,13 +191,18 @@ internal static string GetNanoCLRTypeName(TypeReference parameterType) // check if it's generic return "DATATYPE_GENERICTYPE"; } - else + else if(parameterType.IsPointer) { - // this is not a generic, get full qualified type name - string typeName = parameterType.FullName.Replace(".", String.Empty); - - return CleanupGenericName(typeName); + if (nanoSignaturesTable.PrimitiveTypes.TryGetValue(parameterType.GetElementType().FullName, out myType)) + { + return $"{myType}ptr"; + } } + + // last attempt: get full qualified type name + string typeName = parameterType.FullName.Replace(".", string.Empty); + + return CleanupGenericName(typeName); } } diff --git a/MetadataProcessor.Tests/StubsGenerationTestNFApp/NativeMethodGeneration.cs b/MetadataProcessor.Tests/StubsGenerationTestNFApp/NativeMethodGeneration.cs index c49c1e0a..a17fd0ff 100644 --- a/MetadataProcessor.Tests/StubsGenerationTestNFApp/NativeMethodGeneration.cs +++ b/MetadataProcessor.Tests/StubsGenerationTestNFApp/NativeMethodGeneration.cs @@ -27,5 +27,8 @@ public void Method() [MethodImpl(MethodImplOptions.InternalCall)] private static extern byte NativeStaticMethodReturningByte(char charParam); + + [MethodImpl(MethodImplOptions.InternalCall)] + public extern unsafe void MethodWithPointerParm(void* pointer, int length); } -} \ No newline at end of file +} diff --git a/MetadataProcessor.Tests/StubsGenerationTestNFApp/StubsGenerationTestNFApp.nfproj b/MetadataProcessor.Tests/StubsGenerationTestNFApp/StubsGenerationTestNFApp.nfproj index 70078d50..b09e2019 100644 --- a/MetadataProcessor.Tests/StubsGenerationTestNFApp/StubsGenerationTestNFApp.nfproj +++ b/MetadataProcessor.Tests/StubsGenerationTestNFApp/StubsGenerationTestNFApp.nfproj @@ -15,6 +15,7 @@ StubsGenerationTestNFApp StubsGenerationTestNFApp v1.0 + true True @@ -35,4 +36,4 @@ - \ No newline at end of file +