Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading a Windows DLL in Java and initiate a class from it
    text
    copied!<p>I have a Windows DLL file from .NET, namely "System.Management.dll". I work with it using the code I write below:</p> <pre><code>ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_LogicalDisk WHERE Name = 'C:'"); foreach (ManagementObject queryObj in searcher.Get()) { Console.WriteLine("Win32_LogicalDisk instance: "); if (queryObj["VolumeSerialNumber"] != null) { Console.WriteLine("Drive Name : " + queryObj["Name"]); Console.WriteLine("VolumeSerialNumber:", queryObj["VolumeSerialNumber"]); SysdriveSerial = queryObj["VolumeSerialNumber"].ToString(); } } </code></pre> <p>Now I need this piece of code to be in Java. So can I do this? Without anything like c++ unmanaged code. I don't want to use c++ unmanaged code to call to this dll.</p> <p>I want something like this : </p> <pre><code>public class CallToCsharp { private static native void ManagementObjectSearcher(); public static void main(String[] args) { System.loadLibrary("System.Management"); System.out.println("Loaded"); ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_LogicalDisk WHERE Name = 'C:'"); } } </code></pre> <p>Well this last code I have to put it in Java. How can I load this DLL and call the DLL to instantiate the native class in DLL and use its methods?</p> <h2>Update</h2> <p>I saw the thing, it seems it's a lot of work to do in case I have to use that class, like selecting each of them in .net Reflector and converting them to jar files. Now as per that tutorial I saw the jar files don't contain any real code to be used.</p> <p>How to use it? I mean if I need to generate the jar file actually working with the code enough. How to go about it?</p> <p>And aren't there any alternatives to this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload