JavaでActiveXを作ってやるぜべいびー
セキュリティ的に問題あるのは判っていても、ローカルのHTMLファイルをブラウザで開いて、そこからWSHでローカルのEXEを動かすのになんで認証が必要なんじゃー!って叫びたくなってしまい、ActiveXなんか作ったこともないから逃げてたのに仕方なくやってみようとちょっと調べたら、なんとJavaでActiveXが作れちゃうらしいっすよ。
そのヒントを下さったのがこのページ。
http://www.ytp.ne.jp/tech/java/sineruka/activexhowto.html
でJarを作って、文中の
http://java.sun.com/products/plugin/1.3/docs/ja/script.html
を参考にしてみたら、そんなクラスはねぇ!って怒られた。
よく見るとJDK 1.3じゃん。んじゃ1.4は?と調べると
http://java.sun.com/j2se/1.4.2/docs/guide/beans/axbridge/developerguide/index.html
へ辿り着いた。
%JAVA_HOME%\bin にある packager.exeを使えばできるらしい。おお1.3の時よりも簡単かな?とおもってやってみたら以下のエラーが出た。
midl.exe がないのでタイプライブラリの生成に失敗しました.
そんなEXE知らん!って思ったけど、ページの最初の方をよく見たら、こんなことがしっかり書いてある。
Notes 1. Running the packager (packager.exe) requires that you have the following installed on your computer: * SDK 1.4.2 or higher * Microsoft Visual C++ 6.0 with SP3 2. In order for packager to work you must first run VCVARS32.BAT. cd to the /bin directory where it is located in your Microsoft Visual C++ installation and type VCVARS32.
Visual Studio?もってねーよ!!!
でも諦めが悪いのでまだ調べた。すると、こんなページを発見。
http://forum.java.sun.com/thread.jspa?tstart=0&forumID=40&threadID=522688&trange=15
要するに、
1. www.microsoft.com/msdownload/platformsdk/sdkupdate
からCore SDKをインストールして、
2. http://www.softpedia.com/public/cat/5/6/5-6-96.shtml
とかから Microsoft Visual C++ Toolkit 2003 をダウンロード & インストール
3. C:\Program Files\Microsoft Platform SDK\SetEnv.cmd を実行。必要なパスを環境変数PATHに設定するらしい。
4.C:\Program Files\Microsoft Visual C++ Toolkit 2003\vcvars32.bat を実行。こっちはコンパイラに必要なパスを設定するらしい。
これで、%JAVA_HOME%のpackager.exeが起動できました。(ちなみにc:\windows\system32にもPACKAGER.EXEがある。こっちはGUIアプリだ)
とりあえず実行してみる。
C:\j2sdk1.4.2_08\bin>packager 使用法: Packager [-options] <jar file name> <bean name> オプションは次のとおりです: -clsid <class-id> パッケージ化された Bean の CLSID -out <output directory> パッケージ化された Bean の出力先ディレクトリ -reg Active-X コントロールの登録に同意する
という使い方ができるらしい。
とりあえず打ってみる。
C:\j2sdk1.4.2_08\bin>packager.exe -out D:\dev\asyrinx.org\phase-3\workspace\ExeInvoker D:\dev\asyrinx.org\phase-3\workspace\ExeInvoker\activex.jar org.asyrinx.brownie.activex.ExeInvoker Processing C:\DOCUME~1\takeshi\LOCALS~1\Temp\\ExeInvoker.idl ExeInvoker.idl Processing C:\Program Files\Microsoft Platform SDK\Include\oaidl.idl oaidl.idl Processing C:\Program Files\Microsoft Platform SDK\Include\objidl.idl objidl.idl Processing C:\Program Files\Microsoft Platform SDK\Include\unknwn.idl unknwn.idl Processing C:\Program Files\Microsoft Platform SDK\Include\wtypes.idl wtypes.idl Processing C:\Program Files\Microsoft Platform SDK\Include\basetsd.h basetsd.h Processing C:\Program Files\Microsoft Platform SDK\Include\guiddef.h guiddef.h Processing C:\Program Files\Microsoft Platform SDK\Include\oaidl.acf oaidl.acf
なんだかメッセージはよくわからないけど、-outで指定したディレクトリにDLLができていた。で、どうやらActiveXをレジストリに登録しなきゃならんので、-regも付けてみる。
C:\j2sdk1.4.2_08\bin>packager.exe -out D:\dev\asyrinx.org\phase-3\workspace\ExeInvoker D:\dev\asyrinx.org\phase-3\workspace\ExeInvoker\activex.jar -reg org.asyrinx.brownie.activex.ExeInvoker Processing C:\DOCUME~1\takeshi\LOCALS~1\Temp\\ExeInvoker.idl ExeInvoker.idl Processing C:\Program Files\Microsoft Platform SDK\Include\oaidl.idl oaidl.idl Processing C:\Program Files\Microsoft Platform SDK\Include\objidl.idl objidl.idl Processing C:\Program Files\Microsoft Platform SDK\Include\unknwn.idl unknwn.idl Processing C:\Program Files\Microsoft Platform SDK\Include\wtypes.idl wtypes.idl Processing C:\Program Files\Microsoft Platform SDK\Include\basetsd.h basetsd.h Processing C:\Program Files\Microsoft Platform SDK\Include\guiddef.h guiddef.h Processing C:\Program Files\Microsoft Platform SDK\Include\oaidl.acf oaidl.acf 登録失敗: パッケージ bean の登録は、.dll が <jre_home>\axbridge\bin ディレクトリに格納されている場合にのみ実行されます
って怒られた。-outを指定しなきゃ自動的にやってくれるかなと思ったけどだめ。しょうがないので、ちゃんと指定してみた。
C:\j2sdk1.4.2_08\bin>packager.exe -out C:\j2sdk1.4.2_08\jre\axbridge\bin D:\dev\asyrinx.org\phase-3\workspace\ExeInvoker\activex.jar -reg org.asyrinx.brownie.activex.ExeInvoker Processing C:\DOCUME~1\takeshi\LOCALS~1\Temp\\ExeInvoker.idl ExeInvoker.idl Processing C:\Program Files\Microsoft Platform SDK\Include\oaidl.idl oaidl.idl Processing C:\Program Files\Microsoft Platform SDK\Include\objidl.idl objidl.idl Processing C:\Program Files\Microsoft Platform SDK\Include\unknwn.idl unknwn.idl Processing C:\Program Files\Microsoft Platform SDK\Include\wtypes.idl wtypes.idl Processing C:\Program Files\Microsoft Platform SDK\Include\basetsd.h basetsd.h Processing C:\Program Files\Microsoft Platform SDK\Include\guiddef.h guiddef.h Processing C:\Program Files\Microsoft Platform SDK\Include\oaidl.acf oaidl.acf ディレクトリを作成しています: C:\J2SDK1~1.2_0\jre\axbridge\lib
これでいけるのか?