Hello, Win32 API(IronPython) World!

Posted on 6月 18th, 2012 by cx20

Win32 API(IronPython)

Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
以下は IronPython にて clrtype ライブラリを使用した Win32 API の呼出し例である。

ソースコード

import clr
import clrtype
import System
from System.Reflection import BindingFlags
 
class Win32(object):
    __metaclass__ = clrtype.ClrClass
 
    from System.Runtime.InteropServices import DllImportAttribute
    DllImport = clrtype.attribute(DllImportAttribute)
 
    @staticmethod
    @DllImport("user32.dll")
    @clrtype.accepts(System.IntPtr, System.String, System.String, System.UInt32)
    @clrtype.returns(System.Int32)
    def MessageBox(hwnd, text, caption, type): raise RuntimeError("Runtime Error")
 
Win32.MessageBox(System.IntPtr.Zero, "Hello, Win32 API(IronPython) World!", "Hello, World!", 0)

実行方法

C:¥> ipy hello.py

実行結果

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

Tags:

Categories: .NET, IronPython, Win32 API

コメントを残す

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

WP-SpamFree by Pole Position Marketing