如何使用IKVM com创建的.dll可见? [英] How do I make a .dll created with IKVM com visible?

查看:135
本文介绍了如何使用IKVM com创建的.dll可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了几个帖子,但到目前为止我还没有看到任何解决方案。我有一个.jar文件,我通过 IKVM 转换为.NET DLL。我正在努力弄清楚如何使DLL中的方法可以在excel VBA环境中使用。以下是详细信息。

I have seen a few posts on this, but I haven't seen any solutions so far. I have a .jar file that I'm converting to a .NET DLL via IKVM. I'm trying to figure out how to make the methods in the DLL available inside the excel VBA environment. here are the details.

1。)安装的IKVM&注册它的DLL到GAC

1.) installed IKVM & registered it's DLL's to GAC

2。)运行IKVM创建一个.net .dll(mytest.dll)

2.) ran IKVM to create the a .net .dll (mytest.dll)

ikvmc mytest.jar

3。)注册新的.dll

3.) registered the new .dll

regasm mytest.dll

4。)从这里我创建了一个VB.NET项目,并添加了mytest.dll和IKVM.OpenJDK.Core.dll作为项目的引用。然后我可以访问.NET中的.dll中的方法。这是非常好的!

4.) From here i created a VB.NET project and added mytest.dll and IKVM.OpenJDK.Core.dll as references to the project. I am then able to access the methods within the .dll in .NET. This is great!

5。)我真正想要做的是能够在VBA中使用.dll。最初vba不会直接接受.dll,因为它是一个.net库。我尝试创建一个类型库:

5.) what I really want to do is be able to use the .dll in VBA as well. Initially vba wouldn't accept the .dll directly as it's a .net library. I attempted to create a type library:

regasm /codebase /tlb mytest.dll

这创建了一个很好的.tlb文件,但是它却引发了一个关于库没有被强烈命名的警告。

This created a .tlb file which is nice, but it did throw a warning about the library not being strongly named.

6。)然后我在.vb编辑器中加载.tlb作为参考。这样做,但是当我尝试访问没有显示的方法时。类似地,如果我在对象查看器中查找我的库,我可以看到我的两个类,但不能看到这些类的成员。

6.) then I loaded the .tlb as a reference in my vba editor. This works, however when I try to access the methods nothing shows up. Similarly if I look in the object viewer for my library i can see my two classes but not the members of those classes.

另外,我想我可能还需要不知何故在VBA中引用IKVM.OpenJDK.Core.dll。但是我不能这样做,因为它是一个.NET .dll。

Additionally, I imagine that I probably also need to somehow reference the IKVM.OpenJDK.Core.dll inside VBA as well. However I can't do that either since it's a .NET .dll.

有没有人成功将.jar文件转换成可以用于VBA的东西? / p>

Has anyone had success converting a .jar file into something that can be used with VBA?

推荐答案

我想你总是需要通过COM interop显式标记一个可以使用的类。以下是可从VBA使用的Java类的示例:

I think you always need to explicitly mark a class to be usable via COM interop. Here's an example of a Java class that is usable from VBA:

import cli.System.Runtime.InteropServices.*;

@ClassInterfaceAttribute.Annotation(ClassInterfaceType.__Enum.AutoDual)
public class SampleWidget {
  public int Add(int x, int y) {
    return x + y;
  }
}

以下是编译步骤:


  1. 将IKVM.Runtime.dll和所有IKVM.OpenJDK。*。dll复制到当前目录或GAC中。

  2. 运行ikvmstub mscorlib生成mscorlib.jar。

  3. 创建名为SampleWidget.java的Java源代码,其中包含上述代码。

  4. javac - cp mscorlib.jar ;. SampleWidget.java

  5. ikvmc -out:SampleLibrary.dll SampleWidget.class -r:mscorlib.dll

  6. tlbexp SampleLibrary.dll

  7. regasm / codebase SampleLibrary.dll(此步骤需要管理员权限)

  1. Copy IKVM.Runtime.dll and all IKVM.OpenJDK.*.dll into the current directory or the GAC.
  2. Run "ikvmstub mscorlib" to generate mscorlib.jar.
  3. Create a Java source named SampleWidget.java containing the code above.
  4. javac -cp mscorlib.jar;. SampleWidget.java
  5. ikvmc -out:SampleLibrary.dll SampleWidget.class -r:mscorlib.dll
  6. tlbexp SampleLibrary.dll
  7. regasm /codebase SampleLibrary.dll (this step needs administrator rights)

现在您可以添加对来自VBA的SampleLibrary.tlb,并使用SampleWidget类。

Now you can add a reference to the SampleLibrary.tlb from VBA and use the SampleWidget class.

这篇关于如何使用IKVM com创建的.dll可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆