0
点赞
收藏
分享

微信扫一扫

C#,数值计算——插值和外推,Laplace_interp的计算方法与源程序

瑾谋 2023-11-20 阅读 57

一、背景介绍

现有标准的 win32 com组件,有如下的参数:

属性 值 说明
Program IDyinhai.yh_hb_sctr
COM ClassID
COM ClassName

COClass_yh_hb_sctr

Interface TypeDual Interface
Interface NameIyh_hb_sctr

具有一个方法:

yh_hb_call( string astr_jyhb, string astr_jysr, ref string astr_jysc)

需要使用Java进行调用。

二、采用jacob进行调用

2.1 添加依赖

<dependency>
  <groupId>com.hynnet</groupId>
  <artifactId>jacob</artifactId>
  <version>1.18</version>
</dependency>

 2.2 将dll文件放置在java_home\bin目录中

package com.msip;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;


public class TestCom {
    public static void main(String[] args) {
        ComThread.InitSTA(false);
        ActiveXComponent component = new ActiveXComponent("yinhai.yh_hb_sctr");

        try {
            // 获取 COM 组件的 Dispatch 对象
            Dispatch dispatch = (Dispatch) component.getObject();
            String rest = null ;
            String input = "{}";
            // 直接调用方法
            Variant result = Dispatch.invoke(dispatch, "yh_hb_call", Dispatch.Method,
                    new Object[]{"1101", input,rest}, new int[1]);
            // 获取方法调用的结果
            System.out.println("Result: " + result.toString());
            System.out.println("rest="+rest);
        } finally {
            // 关闭 COM 组件,释放资源
            component.safeRelease();
        }

    }
}

三、遇到的问题

3.1 jdk版本问题,文中的com组件是32位系统的,所以程序的jdk必须也是32位的。

3.2 配套的dll程序必须在类路径中

3.3 代码中的try finally语法块是必须的,否则,机会提示找不到对应的方法名。

举报

相关推荐

0 条评论