jacob传送数组到com以及从com的提取com对修改后的数组参数

前端之家收集整理的这篇文章主要介绍了jacob传送数组到com以及从com的提取com对修改后的数组参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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

原文链接:https://www.f2er.com/vb/261624.html

猜你在找的VB相关文章