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

问题描述

我看到的这几个职位,但我还没有看到任何解决方案为止。我有我通过 IKVM 转换为.NET的DLL一个.jar文件。我试图找出如何使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的海关总署

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。)我真正想要做的是能够使用该.dll在VBA为好。最初,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。)然后我装了.TLB在我的VBA编辑器的参考。这工作,但是当我试图访问没有显示的方法。同样,如果我看在我的库中的对象浏览器,我可以看到我的两个类,但这些类不是成员。

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.

此外,我想,我大概还需要以某种方式引用IKVM.OpenJDK.Core.dll内VBA为好。不过,我不能这样做,要么因为它是一个.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使用?

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

推荐答案

我认为你总是需要明确地标记一类是通过COM互操作使用。这里有一个Java类是可用的VBA的例子:

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包含以上code Java源代码。
  4. 的javac -cp mscorlib.jar ;. SampleWidget.java
  5. ikvmc退房手续:SampleLibrary.dll SampleWidget.class -r:mscorlib.dll中
  6. tlbexp SampleLibrary.dll
  7. regasm / codeBase的SampleLibrary.dll(这一步需要管理员权限)

现在,您可以添加一个参考SampleLibrary.tlb从VBA并使用SampleWidget类。

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

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

08-29 01:13