Hello, COM(BeanShell) World!
Posted on 1月 22nd, 2013 by cx20
COM(BeanShell)
COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
COM を用いて開発された部品であれば言語を問わず利用することができる。
BeanShell 自身には、COM を呼び出す機能を持っていないが、別途ライブラリを経由することで呼び出すことが可能である。
以下は BeanShell より JACOB(JAVA-COM Bridge) ライブラリを使用した COM クライアントの例となっている。
ソースコード
import com.jacob.com.Variant; import com.jacob.activeX.ActiveXComponent; ActiveXComponent shell = new ActiveXComponent("Shell.Application"); Variant hwnd = new Variant(0); Variant title = new Variant("Hello, COM(Jacob) World!"); Variant option = new Variant(0); Variant rootFolder = new Variant(36); Variant[] params = new Variant[] { hwnd, title, option, rootFolder }; Object folder = shell.invoke( "BrowseForFolder", params ); |
実行方法
C:¥> SET CLASSPATH=bsh-2.0b4.jar;jacob.jar;%CLASSPATH% C:¥> java bsh.Interpreter Hello.bsh |
実行結果
+----------------------------------------+ |Browse For Folder [X]| +----------------------------------------+ | Hello, COM(JACOB) Wolrd! | | | | +------------------------------------+ | | |[Windows] | | | | +[addins] | | | | +[AppCompat] | | | | +[AppPatch] | | | | +[assembly] | | | | : | | | | : | | | | : | | | +------------------------------------+ | | [Make New Folder] [ OK ] [Cancel] | +----------------------------------------+ |
Tags: COM