Loading a Windows DLL in Java and initiate a class from it

Posted by Joy on Stack Overflow See other posts from Stack Overflow or by Joy
Published on 2011-01-04T06:40:10Z Indexed on 2011/01/04 6:53 UTC
Read the original article Hit count: 186

Filed under:
|

I have a Windows DLL file from .NET namely "System.Management.dll". I work with it using the code I write below:

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

            }

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.

I want something like this :

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:'");
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about .NET