【发布时间】:2014-11-14 12:08:15
【问题描述】:
我一直在尝试使用 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: Can't map name to 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;
}
}
}
如果能帮我弄清楚这里没有发生什么,我真的很感激。谢谢。
【问题讨论】: