diff --git a/Aaru.Checksums/Aaru.Checksums.csproj b/Aaru.Checksums/Aaru.Checksums.csproj
index f67238c7c..5e7240a42 100644
--- a/Aaru.Checksums/Aaru.Checksums.csproj
+++ b/Aaru.Checksums/Aaru.Checksums.csproj
@@ -27,6 +27,7 @@
snupkg
Natalia Portillo <claunia@claunia.com>
true
+ true
true
true
diff --git a/Aaru.Checksums/Adler32Context.cs b/Aaru.Checksums/Adler32Context.cs
index 7ac619968..6dc1135a4 100644
--- a/Aaru.Checksums/Adler32Context.cs
+++ b/Aaru.Checksums/Adler32Context.cs
@@ -52,7 +52,7 @@ namespace Aaru.Checksums;
///
/// Implements the Adler-32 algorithm
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
-public sealed class Adler32Context : IChecksum
+public sealed partial class Adler32Context : IChecksum
{
internal const ushort ADLER_MODULE = 65521;
internal const uint NMAX = 5552;
@@ -130,17 +130,17 @@ public string End()
#endregion
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern IntPtr adler32_init();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial IntPtr adler32_init();
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int adler32_update(IntPtr ctx, byte[] data, uint len);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int adler32_update(IntPtr ctx, byte[] data, uint len);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int adler32_final(IntPtr ctx, ref uint checksum);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int adler32_final(IntPtr ctx, ref uint checksum);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern void adler32_free(IntPtr ctx);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial void adler32_free(IntPtr ctx);
static void Step(ref ushort preSum1, ref ushort preSum2, byte[] data, uint len, bool useNative,
IntPtr nativeContext)
diff --git a/Aaru.Checksums/CRC16Context.cs b/Aaru.Checksums/CRC16Context.cs
index b508dedf4..f988f658f 100644
--- a/Aaru.Checksums/CRC16Context.cs
+++ b/Aaru.Checksums/CRC16Context.cs
@@ -41,7 +41,7 @@ namespace Aaru.Checksums;
///
/// Implements a CRC16 algorithm
-public class Crc16Context : IChecksum
+public partial class Crc16Context : IChecksum
{
readonly ushort _finalSeed;
readonly bool _inverse;
@@ -198,29 +198,29 @@ public string End()
#endregion
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern IntPtr crc16_init();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial IntPtr crc16_init();
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc16_update(IntPtr ctx, byte[] data, uint len);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc16_update(IntPtr ctx, byte[] data, uint len);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc16_final(IntPtr ctx, ref ushort crc);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc16_final(IntPtr ctx, ref ushort crc);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern void crc16_free(IntPtr ctx);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial void crc16_free(IntPtr ctx);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern IntPtr crc16_ccitt_init();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial IntPtr crc16_ccitt_init();
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc16_ccitt_update(IntPtr ctx, byte[] data, uint len);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc16_ccitt_update(IntPtr ctx, byte[] data, uint len);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc16_ccitt_final(IntPtr ctx, ref ushort crc);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc16_ccitt_final(IntPtr ctx, ref ushort crc);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern void crc16_ccitt_free(IntPtr ctx);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial void crc16_ccitt_free(IntPtr ctx);
static void Step(ref ushort previousCrc, ushort[][] table, byte[] data, uint len)
{
diff --git a/Aaru.Checksums/CRC32Context.cs b/Aaru.Checksums/CRC32Context.cs
index 0f21f068b..409fbe25c 100644
--- a/Aaru.Checksums/CRC32Context.cs
+++ b/Aaru.Checksums/CRC32Context.cs
@@ -49,7 +49,7 @@ namespace Aaru.Checksums;
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
-public sealed class Crc32Context : IChecksum
+public sealed partial class Crc32Context : IChecksum
{
const uint CRC32_ISO_POLY = 0xEDB88320;
const uint CRC32_ISO_SEED = 0xFFFFFFFF;
@@ -426,17 +426,17 @@ public string End()
#endregion
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern IntPtr crc32_init();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial IntPtr crc32_init();
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc32_update(IntPtr ctx, byte[] data, uint len);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc32_update(IntPtr ctx, byte[] data, uint len);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc32_final(IntPtr ctx, ref uint crc);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc32_final(IntPtr ctx, ref uint crc);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern void crc32_free(IntPtr ctx);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial void crc32_free(IntPtr ctx);
static uint[][] GenerateTable(uint polynomial)
{
diff --git a/Aaru.Checksums/CRC64Context.cs b/Aaru.Checksums/CRC64Context.cs
index ce0737785..e0572eaa5 100644
--- a/Aaru.Checksums/CRC64Context.cs
+++ b/Aaru.Checksums/CRC64Context.cs
@@ -48,7 +48,7 @@ namespace Aaru.Checksums;
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
-public sealed class Crc64Context : IChecksum
+public sealed partial class Crc64Context : IChecksum
{
/// ECMA CRC64 polynomial
const ulong CRC64_ECMA_POLY = 0xC96C5795D7870F42;
@@ -371,17 +371,17 @@ public string End()
#endregion
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern IntPtr crc64_init();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial IntPtr crc64_init();
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc64_update(IntPtr ctx, byte[] data, uint len);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc64_update(IntPtr ctx, byte[] data, uint len);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int crc64_final(IntPtr ctx, ref ulong crc);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int crc64_final(IntPtr ctx, ref ulong crc);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern void crc64_free(IntPtr ctx);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial void crc64_free(IntPtr ctx);
static ulong[][] GenerateTable(ulong polynomial)
{
diff --git a/Aaru.Checksums/FletcherContext.cs b/Aaru.Checksums/FletcherContext.cs
index 29ac3b081..ba19742a0 100644
--- a/Aaru.Checksums/FletcherContext.cs
+++ b/Aaru.Checksums/FletcherContext.cs
@@ -50,7 +50,7 @@ namespace Aaru.Checksums;
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
-public sealed class Fletcher32Context : IChecksum
+public sealed partial class Fletcher32Context : IChecksum
{
internal const ushort FLETCHER_MODULE = 0xFFFF;
internal const uint NMAX = 5552;
@@ -128,17 +128,17 @@ public string End()
#endregion
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern IntPtr fletcher32_init();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial IntPtr fletcher32_init();
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int fletcher32_update(IntPtr ctx, byte[] data, uint len);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int fletcher32_update(IntPtr ctx, byte[] data, uint len);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int fletcher32_final(IntPtr ctx, ref uint crc);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int fletcher32_final(IntPtr ctx, ref uint crc);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern void fletcher32_free(IntPtr ctx);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial void fletcher32_free(IntPtr ctx);
static void Step(ref ushort previousSum1, ref ushort previousSum2, byte[] data, uint len, bool useNative,
IntPtr nativeContext)
@@ -418,7 +418,7 @@ public static string Data(byte[] data, uint len, out byte[] hash)
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")]
-public sealed class Fletcher16Context : IChecksum
+public sealed partial class Fletcher16Context : IChecksum
{
const byte FLETCHER_MODULE = 0xFF;
const byte NMAX = 22;
@@ -497,17 +497,17 @@ public string End()
#endregion
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern IntPtr fletcher16_init();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial IntPtr fletcher16_init();
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int fletcher16_update(IntPtr ctx, byte[] data, uint len);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int fletcher16_update(IntPtr ctx, byte[] data, uint len);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern int fletcher16_final(IntPtr ctx, ref ushort checksum);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial int fletcher16_final(IntPtr ctx, ref ushort checksum);
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern void fletcher16_free(IntPtr ctx);
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial void fletcher16_free(IntPtr ctx);
static void Step(ref byte previousSum1, ref byte previousSum2, byte[] data, uint len, bool useNative,
IntPtr nativeContext)
diff --git a/Aaru.Checksums/Native.cs b/Aaru.Checksums/Native.cs
index 5bea1a8dc..e2e48e033 100644
--- a/Aaru.Checksums/Native.cs
+++ b/Aaru.Checksums/Native.cs
@@ -35,7 +35,7 @@
namespace Aaru.Checksums;
/// Handles native implementations of compression algorithms
-public static class Native
+public static partial class Native
{
static bool _checked;
static bool _supported;
@@ -76,6 +76,6 @@ public static bool IsSupported
}
}
- [DllImport("libAaru.Checksums.Native", SetLastError = true)]
- static extern ulong get_acn_version();
+ [LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
+ private static partial ulong get_acn_version();
}
\ No newline at end of file
diff --git a/Aaru.CommonTypes/Aaru.CommonTypes.csproj b/Aaru.CommonTypes/Aaru.CommonTypes.csproj
index b3bed3cdc..f7284937c 100644
--- a/Aaru.CommonTypes/Aaru.CommonTypes.csproj
+++ b/Aaru.CommonTypes/Aaru.CommonTypes.csproj
@@ -27,6 +27,7 @@
snupkg
Natalia Portillo <claunia@claunia.com>
true
+ true
true
diff --git a/Aaru.CommonTypes/Interop/DetectOS.cs b/Aaru.CommonTypes/Interop/DetectOS.cs
index 5011c69a5..fe5eacf4e 100644
--- a/Aaru.CommonTypes/Interop/DetectOS.cs
+++ b/Aaru.CommonTypes/Interop/DetectOS.cs
@@ -40,12 +40,13 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.Marshalling;
using System.Security.Principal;
namespace Aaru.CommonTypes.Interop;
/// Detects the underlying execution framework and operating system
-public static class DetectOS
+public static partial class DetectOS
{
/// Are we running under Mono?
public static readonly bool IsMono =
@@ -98,11 +99,15 @@ public static bool IsAdmin
}
}
- [DllImport("libc", SetLastError = true)]
- static extern int uname(out UtsName name);
+ [LibraryImport("libc", SetLastError = true)]
+ private static partial int uname(out UtsName name);
- [DllImport("libc", SetLastError = true, EntryPoint = "sysctlbyname", CharSet = CharSet.Ansi)]
- static extern int OSX_sysctlbyname(string name, IntPtr oldp, IntPtr oldlenp, IntPtr newp, uint newlen);
+ [LibraryImport("libc",
+ EntryPoint = "sysctlbyname",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Custom,
+ StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
+ private static partial int OSX_sysctlbyname(string name, IntPtr oldp, IntPtr oldlenp, IntPtr newp, uint newlen);
/// Gets the real platform ID, not the incomplete .NET framework one
/// Platform ID
diff --git a/Aaru.Compression/ADC.cs b/Aaru.Compression/ADC.cs
index 464d371b7..1622eaa28 100644
--- a/Aaru.Compression/ADC.cs
+++ b/Aaru.Compression/ADC.cs
@@ -44,7 +44,7 @@ namespace Aaru.Compression;
/// Implements the Apple version of RLE
// ReSharper disable once InconsistentNaming
-public static class ADC
+public static partial class ADC
{
const int PLAIN = 1;
const int TWO_BYTE = 2;
@@ -53,8 +53,8 @@ public static class ADC
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => true;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_adc_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_adc_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static int GetChunkType(byte byt) => (byt & 0x80) == 0x80
diff --git a/Aaru.Compression/AppleRle.cs b/Aaru.Compression/AppleRle.cs
index 8bb06af59..7b22577d3 100644
--- a/Aaru.Compression/AppleRle.cs
+++ b/Aaru.Compression/AppleRle.cs
@@ -36,15 +36,16 @@
namespace Aaru.Compression;
/// Implements the Apple version of RLE
-public static class AppleRle
+public static partial class AppleRle
{
const uint DART_CHUNK = 20960;
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => true;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_apple_rle_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_apple_rle_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer,
+ int srcSize);
/// Decodes a buffer compressed with Apple RLE
/// Encoded buffer
diff --git a/Aaru.Compression/BZip2.cs b/Aaru.Compression/BZip2.cs
index 7b2bb54b0..3585b2330 100644
--- a/Aaru.Compression/BZip2.cs
+++ b/Aaru.Compression/BZip2.cs
@@ -33,17 +33,18 @@
namespace Aaru.Compression;
/// Implements the BZIP2 compression algorithm
-public class BZip2
+public partial class BZip2
{
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => true;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_bzip2_decode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer, uint srcSize);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_bzip2_decode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer,
+ uint srcSize);
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_bzip2_encode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer, uint srcSize,
- int blockSize100K);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_bzip2_encode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer,
+ uint srcSize, int blockSize100K);
/// Decodes a buffer compressed with BZIP2
/// Encoded buffer
diff --git a/Aaru.Compression/FLAC.cs b/Aaru.Compression/FLAC.cs
index 5b635f79c..5b4a04ac9 100644
--- a/Aaru.Compression/FLAC.cs
+++ b/Aaru.Compression/FLAC.cs
@@ -36,23 +36,24 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// Implements the FLAC lossless audio compression algorithm
-public class FLAC
+public partial class FLAC
{
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => true;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern nuint AARU_flac_decode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
- nuint srcSize);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial nuint AARU_flac_decode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
+ nuint srcSize);
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern nuint AARU_flac_encode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
- nuint srcSize, uint blocksize, int doMidSideStereo,
- int looseMidSideStereo, string apodization, uint maxLpcOrder,
- uint qlpCoeffPrecision, int doQlpCoeffPrecSearch,
- int doExhaustiveModelSearch, uint minResidualPartitionOrder,
- uint maxResidualPartitionOrder, string applicationID,
- uint applicationIDLen);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial nuint AARU_flac_encode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
+ nuint srcSize, uint blocksize, int doMidSideStereo,
+ int looseMidSideStereo, string apodization,
+ uint maxLpcOrder, uint qlpCoeffPrecision,
+ int doQlpCoeffPrecSearch, int doExhaustiveModelSearch,
+ uint minResidualPartitionOrder,
+ uint maxResidualPartitionOrder, string applicationID,
+ uint applicationIDLen);
/// Decodes a buffer compressed with FLAC
/// Encoded buffer
diff --git a/Aaru.Compression/LZFSE.cs b/Aaru.Compression/LZFSE.cs
index 444a67317..e4c8c92fb 100644
--- a/Aaru.Compression/LZFSE.cs
+++ b/Aaru.Compression/LZFSE.cs
@@ -32,18 +32,18 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// Implements the LZFSE compression algorithm
-public class LZFSE
+public partial class LZFSE
{
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => Native.IsSupported;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern nuint AARU_lzfse_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
- byte[] scratchBuffer);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial nuint AARU_lzfse_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
+ nuint srcSize, byte[] scratchBuffer);
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern nuint AARU_lzfse_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
- byte[] scratchBuffer);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial nuint AARU_lzfse_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
+ nuint srcSize, byte[] scratchBuffer);
/// Decodes a buffer compressed with LZFSE
/// Encoded buffer
diff --git a/Aaru.Compression/LZIP.cs b/Aaru.Compression/LZIP.cs
index dba82bef3..5bbdd803d 100644
--- a/Aaru.Compression/LZIP.cs
+++ b/Aaru.Compression/LZIP.cs
@@ -32,17 +32,17 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// Implements the LZIP compression algorithm
-public class LZIP
+public partial class LZIP
{
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => Native.IsSupported;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_lzip_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_lzip_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_lzip_encode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize,
- int dictionarySize, int matchLenLimit);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_lzip_encode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize,
+ int dictionarySize, int matchLenLimit);
/// Decodes a buffer compressed with LZIP
/// Encoded buffer
diff --git a/Aaru.Compression/LZMA.cs b/Aaru.Compression/LZMA.cs
index 72c28eb37..fb3d6740a 100644
--- a/Aaru.Compression/LZMA.cs
+++ b/Aaru.Compression/LZMA.cs
@@ -34,19 +34,20 @@
namespace Aaru.Compression;
/// Implements the LZMA compression algorithm
-public class LZMA
+public partial class LZMA
{
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => true;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_lzma_decode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer, ref nuint srcSize,
- byte[] props, nuint propsSize);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_lzma_decode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer,
+ ref nuint srcSize, byte[] props, nuint propsSize);
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern int AARU_lzma_encode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer, nuint srcSize,
- byte[] outProps, ref nuint outPropsSize, int level, uint dictSize, int lc,
- int lp, int pb, int fb, int numThreads);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial int AARU_lzma_encode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer,
+ nuint srcSize, byte[] outProps, ref nuint outPropsSize,
+ int level, uint dictSize, int lc, int lp, int pb, int fb,
+ int numThreads);
/// Decodes a buffer compressed with LZMA
/// Encoded buffer
diff --git a/Aaru.Compression/Native.cs b/Aaru.Compression/Native.cs
index 06c4aea63..e7c802a38 100644
--- a/Aaru.Compression/Native.cs
+++ b/Aaru.Compression/Native.cs
@@ -35,7 +35,7 @@
namespace Aaru.Compression;
/// Handles native implementations of compression algorithms
-public static class Native
+public static partial class Native
{
static bool _checked;
static bool _supported;
@@ -76,6 +76,6 @@ public static bool IsSupported
}
}
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern ulong AARU_get_acn_version();
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial ulong AARU_get_acn_version();
}
\ No newline at end of file
diff --git a/Aaru.Compression/ZSTD.cs b/Aaru.Compression/ZSTD.cs
index 295c754eb..128c984a9 100644
--- a/Aaru.Compression/ZSTD.cs
+++ b/Aaru.Compression/ZSTD.cs
@@ -32,17 +32,18 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// Implements the zstandard compression algorithm
-public class ZSTD
+public partial class ZSTD
{
/// Set to true if this algorithm is supported, false otherwise.
public static bool IsSupported => Native.IsSupported;
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern nuint AARU_zstd_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial nuint AARU_zstd_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
+ nuint srcSize);
- [DllImport("libAaru.Compression.Native", SetLastError = true)]
- static extern nuint AARU_zstd_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
- int compressionLevel);
+ [LibraryImport("libAaru.Compression.Native", SetLastError = true)]
+ private static partial nuint AARU_zstd_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
+ nuint srcSize, int compressionLevel);
/// Decodes a buffer compressed with ZSTD
/// Encoded buffer
diff --git a/Aaru.Devices/Aaru.Devices.csproj b/Aaru.Devices/Aaru.Devices.csproj
index 7dace0ec1..8a35d9171 100644
--- a/Aaru.Devices/Aaru.Devices.csproj
+++ b/Aaru.Devices/Aaru.Devices.csproj
@@ -27,6 +27,7 @@
snupkg
Natalia Portillo <claunia@claunia.com>
true
+ true
true
diff --git a/Aaru.Devices/Linux/Extern.cs b/Aaru.Devices/Linux/Extern.cs
index e2ae2394c..1d3a8f290 100644
--- a/Aaru.Devices/Linux/Extern.cs
+++ b/Aaru.Devices/Linux/Extern.cs
@@ -32,47 +32,64 @@
// ****************************************************************************/
using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.Marshalling;
namespace Aaru.Devices.Linux;
-static class Extern
+static partial class Extern
{
- [DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
- internal static extern int open(string pathname, [MarshalAs(UnmanagedType.U4)] FileFlags flags);
+ [LibraryImport("libc",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Custom,
+ StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
+ internal static partial int open(string pathname, [MarshalAs(UnmanagedType.U4)] FileFlags flags);
- [DllImport("libc")]
- internal static extern int close(int fd);
+ [LibraryImport("libc")]
+ internal static partial int close(int fd);
- [DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
- internal static extern int ioctlSg(int fd, LinuxIoctl request, ref SgIoHdrT value);
+ [LibraryImport("libc", EntryPoint = "ioctl", SetLastError = true)]
+ internal static partial int ioctlSg(int fd, LinuxIoctl request, ref SgIoHdrT value);
- [DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
- internal static extern int ioctlMmc(int fd, LinuxIoctl request, ref MmcIocCmd value);
+ [LibraryImport("libc", EntryPoint = "ioctl", SetLastError = true)]
+ internal static partial int ioctlMmc(int fd, LinuxIoctl request, ref MmcIocCmd value);
- [DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
- internal static extern int readlink(string path, nint buf, int bufsize);
+ [LibraryImport("libc",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Custom,
+ StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
+ internal static partial int readlink(string path, nint buf, int bufsize);
- [DllImport("libc", CharSet = CharSet.Ansi, EntryPoint = "readlink", SetLastError = true)]
- internal static extern long readlink64(string path, nint buf, long bufsize);
+ [LibraryImport("libc",
+ EntryPoint = "readlink",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Custom,
+ StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
+ internal static partial long readlink64(string path, nint buf, long bufsize);
- [DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
- internal static extern nint udev_new();
+ [LibraryImport("libudev", SetLastError = true)]
+ internal static partial nint udev_new();
- [DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
- internal static extern nint udev_device_new_from_subsystem_sysname(nint udev, string subsystem, string sysname);
+ [LibraryImport("libudev",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Custom,
+ StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
+ internal static partial nint udev_device_new_from_subsystem_sysname(nint udev, string subsystem, string sysname);
- [DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
- internal static extern string udev_device_get_property_value(nint udevDevice, string key);
+ [LibraryImport("libudev",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Custom,
+ StringMarshallingCustomType = typeof(AnsiStringMarshaller))]
+ internal static partial string udev_device_get_property_value(nint udevDevice, string key);
- [DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
- internal static extern int ioctlMmcMulti(int fd, LinuxIoctl request, nint value);
+ [LibraryImport("libc", EntryPoint = "ioctl", SetLastError = true)]
+ internal static partial int ioctlMmcMulti(int fd, LinuxIoctl request, nint value);
- [DllImport("libc", SetLastError = true)]
- internal static extern long lseek(int fd, long offset, SeekWhence whence);
+ [LibraryImport("libc", SetLastError = true)]
+ internal static partial long lseek(int fd, long offset, SeekWhence whence);
- [DllImport("libc", SetLastError = true)]
- internal static extern int read(int fd, byte[] buf, int count);
+ [LibraryImport("libc", SetLastError = true)]
+ internal static partial int read(int fd, byte[] buf, int count);
- [DllImport("libc", EntryPoint = "read", SetLastError = true)]
- internal static extern long read64(int fd, byte[] buf, long count);
+ [LibraryImport("libc", EntryPoint = "read", SetLastError = true)]
+ internal static partial long read64(int fd, byte[] buf, long count);
}
\ No newline at end of file
diff --git a/Aaru.Devices/Windows/Extern.cs b/Aaru.Devices/Windows/Extern.cs
index fcc9cee5d..5cd071b55 100644
--- a/Aaru.Devices/Windows/Extern.cs
+++ b/Aaru.Devices/Windows/Extern.cs
@@ -39,85 +39,101 @@
namespace Aaru.Devices.Windows;
[SuppressMessage("ReSharper", "UnusedMember.Global")]
-static class Extern
+static partial class Extern
{
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename,
- [MarshalAs(UnmanagedType.U4)] FileAccess access,
- [MarshalAs(UnmanagedType.U4)] FileShare share,
- nint securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
- [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
- [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
- nint templateFile);
-
- [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
- internal static extern bool DeviceIoControlScsi(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
- ref ScsiPassThroughDirectAndSenseBuffer inBuffer,
- uint nInBufferSize,
- ref ScsiPassThroughDirectAndSenseBuffer outBuffer,
- uint nOutBufferSize, ref uint pBytesReturned, nint overlapped);
-
- [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
- internal static extern bool DeviceIoControlAta(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
- ref AtaPassThroughDirect inBuffer, uint nInBufferSize,
- ref AtaPassThroughDirect outBuffer, uint nOutBufferSize,
- ref uint pBytesReturned, nint overlapped);
-
- [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
- internal static extern bool DeviceIoControlStorageQuery(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
- ref StoragePropertyQuery inBuffer, uint nInBufferSize,
- nint outBuffer, uint nOutBufferSize,
- ref uint pBytesReturned, nint overlapped);
-
- [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
- internal static extern bool DeviceIoControlIde(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
- ref IdePassThroughDirect inBuffer, uint nInBufferSize,
- ref IdePassThroughDirect outBuffer, uint nOutBufferSize,
- ref uint pBytesReturned, nint overlapped);
-
- [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
- internal static extern bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
- nint inBuffer, uint nInBufferSize,
- ref StorageDeviceNumber outBuffer, uint nOutBufferSize,
- ref uint pBytesReturned, nint overlapped);
-
- [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
- internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, nint inBuffer,
- uint nInBufferSize, ref SffdiskQueryDeviceProtocolData outBuffer,
- uint nOutBufferSize, out uint pBytesReturned, nint overlapped);
-
- [DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
- internal static extern bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, byte[] inBuffer,
- uint nInBufferSize, byte[] outBuffer, uint nOutBufferSize,
- out uint pBytesReturned, nint overlapped);
-
- [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
- internal static extern SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, nint enumerator, nint hwndParent,
- DeviceGetClassFlags flags);
-
- [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo, nint devInfo,
- ref Guid interfaceClassGuid, uint memberIndex,
- ref DeviceInterfaceData deviceInterfaceData);
-
- [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo,
- ref DeviceInterfaceData deviceInterfaceData,
- nint deviceInterfaceDetailData,
- uint deviceInterfaceDetailDataSize, ref uint requiredSize,
- nint deviceInfoData);
-
- [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo);
-
- [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- internal static extern bool CloseHandle(SafeFileHandle hDevice);
-
- [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer,
- MoveMethod dwMoveMethod);
-
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern bool ReadFile(SafeFileHandle hFile, byte[] lpBuffer, uint nNumberOfBytesToRead,
- out uint lpNumberOfBytesRead, nint lpOverlapped);
+ [LibraryImport("kernel32.dll",
+ EntryPoint = "CreateFileW",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Utf16)]
+ internal static partial SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr)] string filename,
+ [MarshalAs(UnmanagedType.U4)] FileAccess access,
+ [MarshalAs(UnmanagedType.U4)] FileShare share,
+ nint securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
+ [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
+ [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
+ nint templateFile);
+
+ [LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool DeviceIoControlScsi(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
+ ref ScsiPassThroughDirectAndSenseBuffer inBuffer,
+ uint nInBufferSize,
+ ref ScsiPassThroughDirectAndSenseBuffer outBuffer,
+ uint nOutBufferSize, ref uint pBytesReturned, nint overlapped);
+
+ [LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool DeviceIoControlAta(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
+ ref AtaPassThroughDirect inBuffer, uint nInBufferSize,
+ ref AtaPassThroughDirect outBuffer, uint nOutBufferSize,
+ ref uint pBytesReturned, nint overlapped);
+
+ [LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool DeviceIoControlStorageQuery(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
+ ref StoragePropertyQuery inBuffer, uint nInBufferSize,
+ nint outBuffer, uint nOutBufferSize,
+ ref uint pBytesReturned, nint overlapped);
+
+ [LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool DeviceIoControlIde(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
+ ref IdePassThroughDirect inBuffer, uint nInBufferSize,
+ ref IdePassThroughDirect outBuffer, uint nOutBufferSize,
+ ref uint pBytesReturned, nint overlapped);
+
+ [LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool DeviceIoControlGetDeviceNumber(SafeFileHandle hDevice, WindowsIoctl ioControlCode,
+ nint inBuffer, uint nInBufferSize,
+ ref StorageDeviceNumber outBuffer, uint nOutBufferSize,
+ ref uint pBytesReturned, nint overlapped);
+
+ [LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, nint inBuffer,
+ uint nInBufferSize, ref SffdiskQueryDeviceProtocolData outBuffer,
+ uint nOutBufferSize, out uint pBytesReturned, nint overlapped);
+
+ [LibraryImport("Kernel32.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool DeviceIoControl(SafeFileHandle hDevice, WindowsIoctl ioControlCode, byte[] inBuffer,
+ uint nInBufferSize, byte[] outBuffer, uint nOutBufferSize,
+ out uint pBytesReturned, nint overlapped);
+
+ [LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetClassDevsW")]
+ internal static partial SafeFileHandle SetupDiGetClassDevs(ref Guid classGuid, nint enumerator, nint hwndParent,
+ DeviceGetClassFlags flags);
+
+ [LibraryImport("setupapi.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static partial bool SetupDiEnumDeviceInterfaces(SafeFileHandle hDevInfo, nint devInfo,
+ ref Guid interfaceClassGuid, uint memberIndex,
+ ref DeviceInterfaceData deviceInterfaceData);
+
+ [LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceInterfaceDetailW", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static partial bool SetupDiGetDeviceInterfaceDetail(SafeFileHandle hDevInfo,
+ ref DeviceInterfaceData deviceInterfaceData,
+ nint deviceInterfaceDetailData,
+ uint deviceInterfaceDetailDataSize,
+ ref uint requiredSize, nint deviceInfoData);
+
+ [LibraryImport("setupapi.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static partial bool SetupDiDestroyDeviceInfoList(SafeFileHandle hDevInfo);
+
+ [LibraryImport("Kernel32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static partial bool CloseHandle(SafeFileHandle hDevice);
+
+ [LibraryImport("Kernel32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static partial bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer,
+ MoveMethod dwMoveMethod);
+
+ [LibraryImport("kernel32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static partial bool ReadFile(SafeFileHandle hFile, byte[] lpBuffer, uint nNumberOfBytesToRead,
+ out uint lpNumberOfBytesRead, nint lpOverlapped);
}
\ No newline at end of file
diff --git a/Aaru.Devices/Windows/Usb.cs b/Aaru.Devices/Windows/Usb.cs
index d18142493..4a2d2e16a 100644
--- a/Aaru.Devices/Windows/Usb.cs
+++ b/Aaru.Devices/Windows/Usb.cs
@@ -1170,54 +1170,76 @@ struct UsbNodeConnectionDriverkeyName // Yes, this is the same as the structure
// ********************** API Definitions ************************
- [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
- static extern IntPtr SetupDiGetClassDevs( // 1st form using a ClassGUID
+ [LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetClassDevsW")]
+ private static partial IntPtr SetupDiGetClassDevs( // 1st form using a ClassGUID
ref Guid classGuid, int enumerator, IntPtr hwndParent, int flags);
- [DllImport("setupapi.dll", CharSet = CharSet.Auto)] // 2nd form uses an Enumerator
- static extern IntPtr SetupDiGetClassDevs(int classGuid, string enumerator, IntPtr hwndParent, int flags);
-
- [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern bool SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, IntPtr deviceInfoData,
- ref Guid interfaceClassGuid, int memberIndex,
- ref SpDeviceInterfaceData deviceInterfaceData);
-
- [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr deviceInfoSet,
- ref SpDeviceInterfaceData deviceInterfaceData,
- ref SpDeviceInterfaceDetailData deviceInterfaceDetailData,
- int deviceInterfaceDetailDataSize, ref int requiredSize,
- ref SpDevinfoData deviceInfoData);
-
- [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData,
- int iProperty, ref int propertyRegDataType,
- IntPtr propertyBuffer, int propertyBufferSize,
- ref int requiredSize);
-
- [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, int memberIndex, ref SpDevinfoData deviceInfoData);
-
- [DllImport("setupapi.dll", SetLastError = true)]
- static extern bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);
-
- [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern bool SetupDiGetDeviceInstanceId(IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData,
- StringBuilder deviceInstanceId, int deviceInstanceIdSize,
- out int requiredSize);
-
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize,
- IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned,
- IntPtr lpOverlapped);
-
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode,
- IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes,
- IntPtr hTemplateFile);
-
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- static extern bool CloseHandle(IntPtr hObject);
+ [LibraryImport("setupapi.dll",
+ EntryPoint = "SetupDiGetClassDevsW",
+ StringMarshalling = StringMarshalling.Utf16)] // 2nd form uses an Enumerator
+ private static partial IntPtr SetupDiGetClassDevs(int classGuid, string enumerator,
+ IntPtr hwndParent, int flags);
+
+ [LibraryImport("setupapi.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool SetupDiEnumDeviceInterfaces(IntPtr deviceInfoSet, IntPtr deviceInfoData,
+ ref Guid interfaceClassGuid, int memberIndex,
+ ref SpDeviceInterfaceData
+ deviceInterfaceData);
+
+ [LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceInterfaceDetailW", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool SetupDiGetDeviceInterfaceDetail(IntPtr deviceInfoSet,
+ ref SpDeviceInterfaceData
+ deviceInterfaceData,
+ ref SpDeviceInterfaceDetailData
+ deviceInterfaceDetailData,
+ int deviceInterfaceDetailDataSize,
+ ref int requiredSize,
+ ref SpDevinfoData deviceInfoData);
+
+ [LibraryImport("setupapi.dll",
+ EntryPoint = "SetupDiGetDeviceRegistryPropertyW",
+ SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool SetupDiGetDeviceRegistryProperty(
+ IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData, int iProperty,
+ ref int propertyRegDataType, IntPtr propertyBuffer, int propertyBufferSize,
+ ref int requiredSize);
+
+ [LibraryImport("setupapi.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool SetupDiEnumDeviceInfo(IntPtr deviceInfoSet, int memberIndex,
+ ref SpDevinfoData deviceInfoData);
+
+ [LibraryImport("setupapi.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);
+
+ [LibraryImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceInstanceIdW", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool SetupDiGetDeviceInstanceId(
+ IntPtr deviceInfoSet, ref SpDevinfoData deviceInfoData, StringBuilder deviceInstanceId,
+ int deviceInstanceIdSize, out int requiredSize);
+
+ [LibraryImport("kernel32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer,
+ int nInBufferSize, IntPtr lpOutBuffer,
+ int nOutBufferSize, out int lpBytesReturned,
+ IntPtr lpOverlapped);
+
+ [LibraryImport("kernel32.dll",
+ EntryPoint = "CreateFileW",
+ SetLastError = true,
+ StringMarshalling = StringMarshalling.Utf16)]
+ private static partial IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode,
+ IntPtr lpSecurityAttributes, int dwCreationDisposition,
+ int dwFlagsAndAttributes, IntPtr hTemplateFile);
+
+ [LibraryImport("kernel32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool CloseHandle(IntPtr hObject);
#endregion
}
\ No newline at end of file
diff --git a/Aaru.Devices/Windows/UsbFunctions.cs b/Aaru.Devices/Windows/UsbFunctions.cs
index 8830d7786..f802d5ed4 100644
--- a/Aaru.Devices/Windows/UsbFunctions.cs
+++ b/Aaru.Devices/Windows/UsbFunctions.cs
@@ -164,11 +164,11 @@ static void SearchHubInstanceId(UsbHub hub, ref UsbDevice foundDevice, string in
}
}
- [DllImport("setupapi.dll")]
- static extern int CM_Get_Parent(out uint pdnDevInst, uint dnDevInst, int ulFlags);
+ [LibraryImport("setupapi.dll")]
+ private static partial int CM_Get_Parent(out uint pdnDevInst, uint dnDevInst, int ulFlags);
- [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
- static extern int CM_Get_Device_ID(uint dnDevInst, IntPtr buffer, int bufferLen, int ulFlags);
+ [LibraryImport("setupapi.dll", EntryPoint = "CM_Get_Device_IDW")]
+ private static partial int CM_Get_Device_ID(uint dnDevInst, IntPtr buffer, int bufferLen, int ulFlags);
/// Find a device based upon a Drive Letter
/// Drive letter