日期:2014-05-20  浏览次数:20801 次

谁有java调用.net的dll简单例子
谁有java调用.net的dll简单例子
我用jawin的工程,一直出现org.jawin.COMException: 80070002这个错误,不知道是怎么回事,哪位大哥帮忙指导指导啊~~~~

------解决方案--------------------
网上的EX.参考下:
http://www.jz123.cn/text/2531635.html

------解决方案--------------------
新建一个TestCom.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace TestCom
{
[Guid("B29F1C52-D3F5-43A9-8D66-D33C743B19CB")]
public interface IEncrypt
{
[DispId(1)]
string GetEncrypt(string str, string str2);
}
[Guid("DC1218D6-2FF1-4C20-9DBE-DAFE69EC851E"),
ClassInterface(ClassInterfaceType.None)]
public class Encrypt : IEncrypt
{
public Encrypt() { }
public string GetEncrypt(string str)
{
Console.Write(str );
}
}
}

csc /target:library /out:includecom.dll *.cs
regasm /tlb includecom.dll
生成dll和tlb文件


java:
package demos;

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

public class test {
/** * @param args */
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
ActiveXComponent dotnetCom = null;
dotnetCom = new ActiveXComponent("TestCom.Encrypt");
Variant var = Dispatch.call(dotnetCom, "GetEncrypt", "aaaaaa");
String str = var.toString();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}