Archive for 1月 26th, 2013

  1. Hello, COM(Jasmin) World!

    Posted on 1月 26th, 2013 by cx20

    COM(Jasmin)

    COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
    COM を用いて開発された部品であれば言語を問わず利用することができる。
    Jasmin 自身には、COM を呼び出す機能を持っていないが、別途ライブラリを経由することで呼び出すことが可能である。
    以下は Jasmin より JACOB(JAVA-COM Bridge) ライブラリを使用した COM クライアントの例となっている。

    ソースコード

    ; Produced by NeoJasminVisitor (tinapoc)
    ; http://tinapoc.sourceforge.net
    ; The original JasminVisitor is part of the BCEL
    ; http://jakarta.apache.org/bcel/
    ; Sun Dec 09 17:59:35 JST 2012
     
    .bytecode 51.0
    .source Hello.java
    .class public Hello
    .super java/lang/Object
     
     
    .method public ()V
        .limit stack 1
        .limit locals 1
        .var 0 is this LHello; from Label0 to Label1
     
        Label0:
    .line 4
           0: aload_0
           1: invokespecial java/lang/Object/()V
     
        Label1:
           4: return
     
    .end method
     
     
    .method public static main([Ljava/lang/String;)V
        .limit stack 4
        .limit locals 8
        .var 0 is arg0 [Ljava/lang/String; from Label0 to Label1
     
        Label0:
    .line 6
           0: new com/jacob/activeX/ActiveXComponent
           3: dup
           4: ldc "Shell.Application"
           6: invokespecial com/jacob/activeX/ActiveXComponent/(Ljava/lang/String;)V
           9: astore_1
     
        .line 7
          10: new com/jacob/com/Variant
          13: dup
          14: iconst_0
          15: invokespecial com/jacob/com/Variant/(I)V
          18: astore_2
     
        .line 8
          19: new com/jacob/com/Variant
          22: dup
          23: ldc "Hello, COM(JACOB) World!"
          25: invokespecial com/jacob/com/Variant/(Ljava/lang/String;)V
          28: astore_3
     
        .line 9
          29: new com/jacob/com/Variant
          32: dup
          33: iconst_0
          34: invokespecial com/jacob/com/Variant/(I)V
          37: astore 4
     
        .line 10
          39: new com/jacob/com/Variant
          42: dup
          43: bipush 36
          45: invokespecial com/jacob/com/Variant/(I)V
          48: astore 5
     
        .line 11
          50: iconst_4
          51: anewarray com/jacob/com/Variant
          54: dup
          55: iconst_0
          56: aload_2
          57: aastore
          58: dup
          59: iconst_1
          60: aload_3
          61: aastore
          62: dup
          63: iconst_2
          64: aload 4
          66: aastore
          67: dup
          68: iconst_3
          69: aload 5
          71: aastore
          72: astore 6
     
        .line 12
          74: aload_1
          75: ldc "BrowseForFolder"
          77: aload 6
          79: invokevirtual com/jacob/activeX/ActiveXComponent/invoke(Ljava/lang/String;[Lcom/jacob/com/Variant;)Lcom/jacob/com/Variant;
          82: astore 7
     
        Label1:
    .line 13
          84: return
     
    .end method

    コンパイル&実行方法

    C:¥> jasmin Hello.j
    C:¥> java -cp jacob.jar;. Hello

    実行結果

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