All Projects → AndreyAkinshin → Interopdotnet

AndreyAkinshin / Interopdotnet

Licence: mit
Cross-platform AnyCPU P/Invoke for .NET

Projects that are alternatives of or similar to Interopdotnet

GLFWDotNet
.NET bindings for GLFW.
Stars: ✭ 47 (-64.12%)
Mutual labels:  interop
Enet Csharp
Reliable UDP networking library
Stars: ✭ 464 (+254.2%)
Mutual labels:  interop
Smmalloc Csharp
Blazing fast memory allocator designed for video games meets .NET
Stars: ✭ 81 (-38.17%)
Mutual labels:  interop
Vst.net
Virtual Studio Technology (VST) for .NET. Plugins and Host applications.
Stars: ✭ 267 (+103.82%)
Mutual labels:  interop
Vuera
👀 Vue in React, React in Vue. Seamless integration of the two. 👯
Stars: ✭ 3,631 (+2671.76%)
Mutual labels:  interop
Minimal
A Delightfully Diminutive Lisp. Implemented in < 1 KB of JavaScript with JSON source, macros, tail-calls, JS interop, error-handling, and more.
Stars: ✭ 560 (+327.48%)
Mutual labels:  interop
swift-bridge
swift-bridge facilitates Rust and Swift interop.
Stars: ✭ 260 (+98.47%)
Mutual labels:  interop
Reactivetradercloud
Real-time FX trading showcase by Adaptive.
Stars: ✭ 1,664 (+1170.23%)
Mutual labels:  interop
Clojure.java Time
Java 8 Date-Time API for Clojure
Stars: ✭ 323 (+146.56%)
Mutual labels:  interop
Cppast.codegen
An extensible library providing C# PInvoke codegen from C/C++ files for .NET
Stars: ✭ 65 (-50.38%)
Mutual labels:  interop
Valvesockets Csharp
Managed C# abstraction of GameNetworkingSockets library by Valve Software
Stars: ✭ 273 (+108.4%)
Mutual labels:  interop
Cljs Oops
ClojureScript macros for convenient native Javascript object access.
Stars: ✭ 293 (+123.66%)
Mutual labels:  interop
Embeddinator 4000
Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
Stars: ✭ 735 (+461.07%)
Mutual labels:  interop
rubylisp
A Lisp dialect of Ruby
Stars: ✭ 20 (-84.73%)
Mutual labels:  interop
Pinvoke
A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
Stars: ✭ 1,288 (+883.21%)
Mutual labels:  interop
rust-lang-interop
Rust language interoperability with other languages - C, C++ etc.
Stars: ✭ 53 (-59.54%)
Mutual labels:  interop
Vanara
A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
Stars: ✭ 544 (+315.27%)
Mutual labels:  interop
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-7.63%)
Mutual labels:  interop
Java.interop
Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Stars: ✭ 120 (-8.4%)
Mutual labels:  interop
Vk denoise
Denoising a Vulkan ray traced image using OptiX denoiser
Stars: ✭ 41 (-68.7%)
Mutual labels:  interop

InteropDotNet

The library allows you to work with native libraries. Standard approach with the DllImport attribute may be inconvenient if you want to build AnyCPU assembly with MS.NET/Mono support. The InteropRuntimeImplementer class can generate implementation of interface with target signatures of native methods.

For example, let's create a native library (NativeLib) with the function int sum(int a, int b) { return a + b; } and build it in four configuration (Windows/Unix, x86/x64):

x86/NativeLib.dll
x86/libNativeLib.so
x64/NativeLib.dll
x64/libNativeLib.so

Now we can write the following code:

public interface INative
{
    [RuntimeDllImport("NativeLib", CallingConvention = CallingConvention.Cdecl, EntryPoint = "sum")]
    int Sum(int a, int b);
}

class Program
{
    static void Main()
    {
        var native = InteropRuntimeImplementer.CreateInstance<INative>();
        Console.WriteLine("2 + 3 = " + native.Sum(2, 3));
    }
}

In the program, we declared interface INative with signatures of the target native methods. Each signature should be marked with the RuntimeDllImport attribute with name of a native library and other options. The instance of InteropRuntimeImplementer helped us to create instance of the INative interface on the fly. The implementation of the sum method call corresponding native method from library that correspond to current architecture and OS. The InteropRuntimeImplementer generates the following code:

namespace InteropRuntimeImplementer.NativeInstance
{
  [UnmanagedFunctionPointer(CallingConvention.Cdecl, BestFitMapping = false, CharSet = (CharSet) 0, SetLastError = false, ThrowOnUnmappableChar = false)]
  [StructLayout(LayoutKind.Auto, CharSet = CharSet.Auto)]
  public delegate int SumDelegate(int a, int b);

  public class NativeImplementation : INative
  {
    private SumDelegate SumField;

    public NativeImplementation(LibraryLoader loader)
    {
      IntPtr dllHandle = loader.LoadLibrary("NativeLib", (string) null);
      this.SumField = (SumDelegate) Marshal.GetDelegateForFunctionPointer(loader.GetProcAddress(dllHandle, "sum"), typeof (SumDelegate));
    }

    public int Sum(int a, int b)
    {
      return this.SumField(a, b);
    }
  }
} 

As a result, we received a single .NET cross-platform AnyCPU-program with calls of native methods because of the LibraryLoader class loaded handles for specific user environment.

NuGet

You can install the library via NuGet: https://www.nuget.org/packages/InteropDotNet/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].