Hello, Win32 API(ClojureCLR) World!
Posted on 6月 21st, 2012 by cx20
Win32 API(ClojureCLR)
Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
ClojureCLR には Win32 API を直接呼び出す機能は実装されていないが、C# を経由することで、Win32 API を呼び出すことが可能となっている。
ソースコード(C#)
using System;
using System.Runtime.InteropServices;
namespace Win32Lib
{
public class Win32
{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public extern static uint MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);
}
} |
using System;
using System.Runtime.InteropServices;
namespace Win32Lib
{
public class Win32
{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public extern static uint MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);
}
}
コンパイル方法(C#)
C:¥> csc /target:library Win32Lib.cs |
C:¥> csc /target:library Win32Lib.cs
ソースコード(ClojureCLR)
(System.Reflection.Assembly/LoadFrom "Win32Lib.dll")
(Win32Lib.Win32/MessageBox 0 "Hello, Win32 API(ClojureCLR) World!" "Hello, World!", 0 ) |
(System.Reflection.Assembly/LoadFrom "Win32Lib.dll")
(Win32Lib.Win32/MessageBox 0 "Hello, Win32 API(ClojureCLR) World!" "Hello, World!", 0 )
実行方法
C:¥> Clojure.Main hello.clj |
C:¥> Clojure.Main hello.clj
実行結果
---------------------------
Hello, World!
---------------------------
Hello, Win32 API(ClojureCLR) World!
---------------------------
OK
--------------------------- |
---------------------------
Hello, World!
---------------------------
Hello, Win32 API(ClojureCLR) World!
---------------------------
OK
---------------------------
Tags: Win32 API
Categories: .NET, ClojureCLR, Win32 API