PlatformInvoker

Loosely bound platform invocation for .NET.

Intended to remove the need for static classes

when using P/Invoke. Supply an interface to

the builder and get an implementation back.

What does it support?

Mocking P/Invoke functions without manually writing a wrapper.

Adding pre-call and post-call probing which allows exceptions

for GetLastError() in the error handling pattern common in C

libraries.

for GetLastError() in the error handling pattern common in C libraries. Marshal attributes still work.

Both 32-bit and 64-bit is supported.

Unix support on Mono and .NET Core

Can support libraries that implement extension systems like OpenAL and OpenGL by implementing

ILibrary.

Example

using System; using Platform.Invoke; using System.Runtime.InteropServices; namespace Example { public interface IMessageBox { int MessageBox(IntPtr hWnd, [In]string lpText, [In]string lpCaption, uint uType); } public class Program { static void Main() { var msg = LibraryInterfaceFactory.Implement<IMessageBox>("user32"); msg.MessageBox(IntPtr.Zero, "Hello World!", "Hello World!", 1); } } }

Example with probing and attributes