开发者

How to call a dll file from c#

开发者 https://www.devze.com 2023-03-26 03:29 出处:网络
I am trying to call a dll file from c# The dll file is made from a java application using ikvm and for now all the code does is print hello world.

I am trying to call a dll file from c#

The dll file is made from a java application using ikvm and for now all the code does is print hello world.

How do i call the dll file in my c# code and is it possible to create an application in java that will return a boolea开发者_开发百科n value to my c# code?

Thanks for your time.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消