Skip to content

OwenMcDonnell/AdvanceDLSupport

 
 

Repository files navigation

AdvanceDLSupport

Alternative approach to your usual P/Invoke!

Use C# interfaces to bind to native code - quick and easy usage of C API in C# code, on any platform. Gone are the days of broken DllImport and annoying workarounds for the different runtimes.

Fully compatible with Mono, .NET Framework, .NET Core, and .NET Standard. Compatible with Mono DLL mapping on all platforms and runtimes. Configurable and adaptible.

Build & Test status

Travis (Linux) Travis (OSX) AppVeyor (Windows) MyGet (Development)
Build Status Build Status Build status Build Status

Read the Docs, or get the MyGet development packages and get started.

Features

  • Supports all the typical P/Invoke patterns and constructs
  • Seamlessly mix native functions and managed code
  • Use more complex types, such as Nullable<T> and string without any extra code
  • Select library architectures at runtime
  • Select library names at runtime
  • Swappable native library search algorithms
  • Import global variables
  • Optional lazy loaded symbols
  • Optional Mono DllMap support

Basic Usage

  1. Declare your interface

    public interface IMyNativeLibrary
    {
    	long MyNativeGlobal { get; set; }
    	int MyNativeMultiply(int a, int b);
    	void MyOtherNativeFunction(MyStruct strct, ref MyStruct? maybeStruct);
    }
  2. Activate it

    const string MyLibraryName = "MyLibrary";
    
    var activator = new NativeLibraryBuilder();
    var library = activator.ActivateInterface<IMyNativeLibrary>(MyLibraryName);
  3. Use it

    library.MyNativeGlobal = 10;
    
    var result = library.MyNativeMultiply(5, 5);
    
    var myStruct = new MyStruct();
    MyStruct? myOtherStruct = null;
    
    library.MyOtherNativeFunction(myStruct, ref myOtherStruct);

See the Quickstart for more information.

Installation

Via your favourite Nuget UI, or

NuGet

Install-Package AdvancedDLSupport -ProjectName MyProject

MyGet

nuget sources Add -Name AdvancedDLSupport-develop -Source https://www.myget.org/F/advancedlsupport/api/v3/index.json
Install-Package AdvancedDLSupport -ProjectName MyProject

License

AdvancedDLSupport is licensed under the GNU General Public License, Version 3 (GPLv3). See the LICENSE for details. Without the support of the open-source movement, it would never have existed.

We also offer custom licensing for companies and individuals. Contact us for a quote.

About

Alternative approach to your usual P/Invoke!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 97.9%
  • C 1.4%
  • CMake 0.7%