How do I make a .dll created with IKVM com visible?

廉价感情. 提交于 2019-11-29 06:58:35

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;
  }
}

Here are the steps to compile:

  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)

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!