Hello, COM(IronPython) World!

Posted on 2月 1st, 2013 by cx20

COM(IronPython)

COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
COM を用いて開発された部品であれば言語を問わず利用することができる。
以下は IronPython による COM クライアントの例となっている。

ソースコード(実行時バインディング)

import System
from System.Reflection import BindingFlags
from System.Runtime.InteropServices import Marshal
 
objType = System.Type.GetTypeFromProgID("Shell.Application")
shell = System.Activator.CreateInstance(objType)
param = System.Array[System.Object]([ 0, "Hello, COM(IronPython) World!", 0, 36 ])
folder = shell.GetType().InvokeMember( "BrowseForFolder", BindingFlags.InvokeMethod, None, shell, param )
if folder != None:
    Marshal.ReleaseComObject(folder)
Marshal.ReleaseComObject(shell)

コンパイル方法(実行時バインディング)

C:¥> ipy Hello.py

実行結果

+----------------------------------------+
|Browse For Folder                    [X]|
+----------------------------------------+
| Hello, COM(IronPython) Wolrd!          |
|                                        |
| +------------------------------------+ |
| |[Windows]                           | |
| | +[addins]                          | |
| | +[AppCompat]                       | |
| | +[AppPatch]                        | |
| | +[assembly]                        | |
| |     :                              | |
| |     :                              | |
| |     :                              | |
| +------------------------------------+ |
| [Make New Folder]    [  OK  ] [Cancel] |
+----------------------------------------+

Tags:

Categories: .NET, COM, IronPython

コメントを残す

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

WP-SpamFree by Pole Position Marketing