PInvoke (tutorial) - vilinski/nemerle GitHub Wiki

You can take advantage of native platform libraries from within Nemerle programs. The syntax is very similar to C#'s and other .NET languages. Here is the simplest examlple:

using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest
{
    [DllImport("msvcrt.dll")]
    public extern static puts(c : string) : int;

    [DllImport("msvcrt.dll")]
    internal extern static _flushall() : int;

    public static Main() : void
    {
        _ = puts("Test");
        _ = _flushall();
    }
}

As you can see we use DllImport attribute, which comes from System.Runtime.InteropServices namespace. Every method marked with this attribute should also have extern modifier. The concept is that the implementation of given method is substituted by call to unmanaged method from library specified inside DllImport attribute.

So, in above example, during execution of Main method first the puts function from msvcrt.dll will be called (printing a text to the standard output) and after that _flushall (making sure that all contents of buffer are printed).

For more see P/Invoke tutorial from MSDN.

⚠️ **GitHub.com Fallback** ⚠️