Gsof.Native 0.4.5

dotnet add package Gsof.Native --version 0.4.5
NuGet\Install-Package Gsof.Native -Version 0.4.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gsof.Native" Version="0.4.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gsof.Native --version 0.4.5
#r "nuget: Gsof.Native, 0.4.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Gsof.Native as a Cake Addin
#addin nuget:?package=Gsof.Native&version=0.4.5

// Install Gsof.Native as a Cake Tool
#tool nuget:?package=Gsof.Native&version=0.4.5

Gsof.Native

  • 支持动态加载 动态库
  • 支持根据进程,查找 x86x64armarm64 目录中同名 动态库
  • 支持 Linux ,在 WSL Ubuntu 中测试。
  • 支持 Buffer 类,简化内存操作。

使用

libtest.dll 为 中包括一个test函数

int test(int input)
{
    return input;
}

方法名调用

int input = 0;
int result = -1;
using (var native = NativeFactory.Create(@"../../libtest.dll"))
{
    result = native.Invoke<int>("test", input);
}

dynamic 方式调用

  • 优点:调用方便,简单类型调用时,不用做过多的定义。
  • 缺点:4.0下性能不理想,4.5+性能好很多,但相较于委托的方式,还差些。
int input = 0;
int result = -1;
using (dynamic native = NativeFactory.Create(@"../../libtest.dll"))
{
    result = native.test<int>(input);
}

委托方式调用

  • 优化:效率高,没有了第一次动态构造委托的消耗,可获取到函数委托增加 重复调用消耗
  • 缺点:如果函数较多,委托定义较为繁琐
[NativeFuncton("test")]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int Test(int p_sleep);

public void DelegateFunction()
{
    int input = 0;
    int result = -1;
    using (var native = NativeFactory.Create(@"../../libtest.dll"))
    {
        // 直接调用
        var result1 = native1.Invoke<int, Test>(input);

        // 获取函数委托调用
        var test = native.GetFunction<Test>();
        result = test(input);
    }

    Assert.AreEqual(input, result);
}

Todo List

  • 支持自动识别 x86 和 x64 目录
  • 支持 Linux
  • 支持 Mac
  • 支持 arm 和 arm64 目录
  • [] 支持 Mac 与 arm 的测试
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

  • .NETFramework 4.5

  • .NETFramework 4.6

  • net5.0

  • net6.0

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Gsof.Native:

Package Downloads
Gsof.System.Token

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.5 144 5/11/2023
0.4.3 117 5/10/2023
0.4.2 182 3/21/2023
0.4.1 244 2/2/2023
0.4.0 228 2/1/2023
0.3.0 287 12/5/2022
0.2.4 392 12/1/2022
0.2.3 289 11/30/2022
0.2.2 284 11/30/2022
0.2.1 283 11/30/2022
0.2.0 274 11/29/2022
0.1.2 416 12/16/2020
0.1.1 995 1/12/2017
0.1.0 887 1/12/2017