JAcobは配列をcomに転送し,comの抽出comから修正した配列パラメータに対して

1483 ワード

import com.jacob.com.*;
  import com.jacob.activeX.*;
  public class Exam_6
  {
   public static void main(String[] args)
   {
   ActiveXComponent pp = new ActiveXComponent("PrjCOM.MyCOM");
   try {
   SafeArray sa = new SafeArray(Variant.VariantString,2);
   Variant var = new Variant();
   sa.fromStringArray(new String[]{"H","H"});
   var.putSafeArrayRef(sa);// 
   // , , putSafeArray 
   Dispatch.call(pp, "Test",var);
   String[] sack= sa.toStringArray();
   System.out.println(sack[0]+"\t"+sack[1]);
   } catch (Exception e) {
   e.printStackTrace();
   }
   }
  }

 
VB実装のComオブジェクトは以下の通りである.
  VERSION 1.0 CLASS
  BEGIN
   MultiUse = -1 'True
   Persistable = 0 'NotPersistable
   DataBindingBehavior = 0 'vbNone
   DataSourceBehavior = 0 'vbNone
   MTSTransactionMode = 0 'NotAnMTSObject
  END
  Attribute VB_Name = "MyCOM"
  Attribute VB_GlobalNameSpace = False
  Attribute VB_Creatable = True
  Attribute VB_PredeclaredId = False
  Attribute VB_Exposed = True
  Public Sub Test(ByRef param() As String)
  ReDim param(2)
  param(0) = "Hello"
  param(1) = "World"
  End Sub

 
コンパイル実行Exam_6.java印刷Hello World