How to call a dll file from c#

喜你入骨 提交于 2019-12-06 05:52:09

I'm not sure I understand what you're trying to do, so apologies if I'm misreading. IKVM should translate your java code to a .NET dll or executable. After the "translation" you should be able to use the .dll more or less in the same way as you would with a "native" .NET code.

If your java application has a main method that prints "hello world" on the console, you should have converted it to a .NET executable (.exe) and not to a dll. After converting it to a .exe (and assuming you're running it on Microsoft .NET on a windows system) you should just execute it.

As for the second part of your question, you can also create a dll (converted from java) that returns a boolean and consume it from a C# application.

See this tutorial for two examples of (pretty much exactly) what you're doing.

sealz
using System.Runtime.InteropServices;

You can then use

[DllImport("myjavadll.dll")]

Then add the dll as a reference by right clicking and navigating to it in the reference folder.

EDIT:

Here is a link that calls a C++ dll to C#. You may be able to work it out.

Call another languages DLL

EDIT: I have had issues adding DLLs as references and was forced to add as a resource. I believe this was because I was working with a sys32 dll.

Here is an old post by where I was trying to work out some DLL import errors. Maybe itll be helpful if you encounter some problems.

Old Post

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