Skip to content

A library loader for loading native functions as unmanaged delegate pointers to archive the best performance

License

Notifications You must be signed in to change notification settings

zmarlon/NativeFunctionLoader

Repository files navigation

NativeFunctionLoader

A library loader for loading native functions as unmanaged delegate pointers to archive the best performance

Platforms supported:

  • Windows
  • MacOS
  • Linux

Supported NET Version:

  • NET 6

Code example:

 public static unsafe class Program {
        [NativeFunction(Platforms.Windows, "user32.dll")]
        public static readonly delegate* unmanaged<void*, char*, char*, uint, int> MessageBoxW;

        static Program() {
            NativeFunctionLoader.Load(typeof(Program));
        }
        
        public static void Main(string[] args) {
            var caption = (char*)Marshal.StringToHGlobalUni("Information").ToPointer();
            var message = (char*)Marshal.StringToHGlobalUni("Hello world!");
            
            MessageBoxW(null, message, caption, 0);
            
            Marshal.FreeHGlobal(new IntPtr(caption));
            Marshal.FreeHGlobal(new IntPtr(message));
            
            NativeFunctionLoader.Free();
        }
    }

About

A library loader for loading native functions as unmanaged delegate pointers to archive the best performance

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages