Hello, COM(IronRuby) World!

Posted on 2月 2nd, 2013 by cx20

COM(IronRuby)

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

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

require 'mscorlib'
include System
include System::Reflection
include System::Runtime::InteropServices
 
objType = System::Type.GetTypeFromProgID("Shell.Application")
shell = System::Activator.CreateInstance(objType)
 
hwnd = 0
title = "Hello, COM(IronRuby) World!".to_clr_string
option = 0
rootFolder = 36
params = System::Array[System::Object].new [hwnd, title, option, rootFolder]
 
folder = shell.GetType().InvokeMember( "BrowseForFolder", BindingFlags.InvokeMethod, nil, shell, params )
if folder != nil then
    System::Runtime::InteropServices::Marshal.ReleaseComObject(folder)
end
System::Runtime::InteropServices::Marshal.ReleaseComObject(shell)

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

C:¥> ir Hello.rb

実行結果

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

Tags:

Categories: .NET, COM, IronRuby

コメントを残す

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

WP-SpamFree by Pole Position Marketing