Hello, Win32 API(IronRuby) World!

Posted on 6月 19th, 2012 by cx20

Win32 API(IronRuby)

Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
IronRuby には 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);
    }
}

コンパイル方法(C#)

C:¥> csc /target:library Win32Lib.cs

ソースコード(IronRuby)

require 'System'
require 'Win32Lib'
include System
include Win32Lib
 
Win32.MessageBox( IntPtr.Zero, "Hello, Win32 API(IronRuby) World!", "Hello, World!", 0 )

実行方法

C:¥> ir hello.rb

実行結果

---------------------------
Hello, World!
---------------------------
Hello, Win32 API(IronRuby) World!
---------------------------
OK   
---------------------------

Tags:

Categories: .NET, IronRuby, Win32 API

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

WP-SpamFree by Pole Position Marketing