From 810cc5751071c9d321a438671ef39e95b3490e57 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 16 Feb 2021 13:15:29 -0700 Subject: [PATCH] Map LARGE_INTEGER structs to 64-bit int types on .NET Closes #69 --- src/Microsoft.Windows.CsWin32/Generator.cs | 6 ++++++ test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs | 1 + 2 files changed, 7 insertions(+) diff --git a/src/Microsoft.Windows.CsWin32/Generator.cs b/src/Microsoft.Windows.CsWin32/Generator.cs index 6e9b47f6..f24247b0 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.cs @@ -34,11 +34,17 @@ public class Generator : IDisposable { { nameof(System.Runtime.InteropServices.ComTypes.FILETIME), ParseTypeName("System.Runtime.InteropServices.ComTypes.FILETIME") }, { nameof(Guid), ParseTypeName("System.Guid") }, + { "OLD_LARGE_INTEGER", PredefinedType(Token(SyntaxKind.LongKeyword)) }, + { "LARGE_INTEGER", PredefinedType(Token(SyntaxKind.LongKeyword)) }, + { "ULARGE_INTEGER", PredefinedType(Token(SyntaxKind.ULongKeyword)) }, }; internal static readonly Dictionary BannedAPIs = new Dictionary { { "GetLastError", "Do not generate GetLastError. Call Marshal.GetLastWin32Error() instead. Learn more from https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.getlastwin32error" }, + { "OLD_LARGE_INTEGER", "Use the C# long keyword instead." }, + { "LARGE_INTEGER", "Use the C# long keyword instead." }, + { "ULARGE_INTEGER", "Use the C# ulong keyword instead." }, }; private const string SystemRuntimeCompilerServices = "System.Runtime.CompilerServices"; diff --git a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs index ecd51c51..f4d8e116 100644 --- a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs +++ b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs @@ -110,6 +110,7 @@ public void SimplestMethod() [InlineData("DsGetDcOpen")] // allocates a handle with a release function that returns HRESULT [InlineData("DXVAHDSW_CALLBACKS")] // pointers to handles [InlineData("HBITMAP_UserMarshal")] // in+out handle pointer + [InlineData("GetDiskFreeSpaceExW")] // ULARGE_INTEGER replaced with keyword: ulong. public void InterestingAPIs(string api) { this.generator = new Generator(this.metadataStream, options: new GeneratorOptions { EmitSingleFile = true }, compilation: this.compilation, parseOptions: this.parseOptions);