I've been trying to call a dll function from Java using Jacob without any success. I have done registration of the dll with regasm as described here - http://www.dreamincode.net/forums/topic/114094-using-dll-library-in-java-application-using-jacob/. My code:
String serverName = "...", fileName = "...";
Dispatch dispatch = new Dispatch("dllx32conn.dbconn");
Dispatch.call(dispatch, "pass_para", serverName, fileName);
This doesn't work. It throws com.jacob.com.ComFailException: Can't map name to dispid: pass_para
So I decided to analyze the dll functions by decompiling it using JetBrains dotPeek. Here is what I found
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;
}
}
}
I would really appreciate some help with figuring out what's not happening here. Thanks.
Problem solved - I just had to remove the 'static' function declaration from my DLL methods thanks to this article - http://jumbloid.blogspot.com/2009/12/making-net-dll-com-visible.html