Loading a Windows DLL in Java and initiate a class from it
- by Joy
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:'");
}
}