Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PInvoke (tutorial)

Alex Zimin edited this pageJul 11, 2011 ·3 revisions

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")]publicexternstatic puts(c :string) :int;    [DllImport("msvcrt.dll")]internalexternstatic _flushall() :int;publicstatic Main() :void    {_ = puts("Test");_ = _flushall();    }}

As you can see we useDllImport attribute, which comes fromSystem.Runtime.InteropServices namespace. Every method marked with this attribute should also haveextern modifier. The concept is that the implementation of given method is substituted by call to unmanaged method from library specified insideDllImport attribute.

So, in above example, during execution ofMain method first theputs function frommsvcrt.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 seeP/Invoke tutorial from MSDN.

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp