java - 雅各布 com.jacob.com.ComFailException : Can't map name to dispid:

标签 java .net jacob

我一直在尝试使用 Jacob 从 Java 调用 dll 函数,但没有成功。我已经按照此处所述使用 regasm 完成了 dll 的注册 - http://www.dreamincode.net/forums/topic/114094-using-dll-library-in-java-application-using-jacob/ 。我的代码:

String serverName = "...", fileName = "...";
Dispatch dispatch = new Dispatch("dllx32conn.dbconn");  
Dispatch.call(dispatch, "pass_para", serverName, fileName);

这行不通。它抛出 com.jacob.com.ComFailException: 无法将名称映射到 dispid: pass_para

因此我决定使用 JetBrains dotPeek 反编译来分析 dll 函数。这是我发现的

using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace dllx32conn
{
  public class dbconn
  {
    public static string conn_str = "";
    public static string strFilePath = "";
    public static SqlConnection Conn = new SqlConnection();
    public static DataTable tbl;
    public static SqlDataAdapter dap;

    public static void pass_para(string servname, string csvpth)
    {
      dbconn.conn_str = "Data Source=" + servname + ";Initial Catalog=Billing;User Id=Scd;Password=Smart11Siri";
      dbconn.strFilePath = csvpth;
    }
  }
}

我真的很感谢一些帮助来弄清楚这里没有发生什么。谢谢。

最佳答案

问题已解决 - 由于这篇文章,我只需从 DLL 方法中删除“静态”函数声明 - http://jumbloid.blogspot.com/2009/12/making-net-dll-com-visible.html

using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace dllx32conn
{
  public class dbconn
  {
    public static string conn_str = "";
    public static string strFilePath = "";
    public static SqlConnection Conn = new SqlConnection();
    public static DataTable tbl;
    public static SqlDataAdapter dap;

    public void pass_para(string servname, string csvpth)
    {
      dbconn.conn_str = "Data Source=" + servname + ";Initial Catalog=xxx;User Id=xxx;Password=xxx";
      dbconn.strFilePath = csvpth;
    }
  }
}

关于java - 雅各布 com.jacob.com.ComFailException : Can't map name to dispid:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26929686/

相关文章:

Java泛型和数组初始化

.net - 在 .Net 中,如何针对实例执行 SQL Server 脚本?

C# 和在内存中存储数据

java - 使用 Jacob 从远程系统读取 Windows 注册表信息

Java、Jacob 和 Microsoft Word : how to properly handle events?

java - Java项目中国际象棋AI的实现

java - 扫描仪未扫描所有字段?

java - 如何在 Java 中配置 .dll 文件?

java - 为什么 apk 不自动安装在三星设备上

.net - 在 .Net 中动态构建文件路径