Does anyone know how to use WMI with C instead of C ++?
I'd love to retrain C ++ just for this! Any libraries / urls would be great and yes, Google didn't help here :-(
This is for an upcoming project where my product (Java based) will provide support for the Microsoft Hyper-V virtualization platform. Unlike VMware, which provides a web service, the Hyper-V APIs are simply extensions to WMI. I would rather not use commercial tools like J-Integra for Java integration in COM / WMI, and several open source tools I found are out of date.
I would rather use JNI with C than C ++. Does anyone know where I can find libraries and so on for using C operations for WMI? In the same vein as Python clients? (And yes, I know C is not OOP: D).
Thanks in advance.
WMI runs through COM correctly?
Although it is more verbose and more error prone (it is easy to accidentally use different pointers for the vtable and "this" parameter), you can also use COM from the C language.
You can also use C ++, but refer to it as "C with language extensions to make COM easier to use".
source to share
The JNI itself is a COM derivative, and you will find these WMI methods and methods much easier to use if you use enough C ++ to handle the interfaces implemented in C ++ classes.
Another useful thing is that you can use COM interface pointers and reference counting as a way to tie the COM lifecycle to the Java classes implemented by the JNI.
I used this approach to implement Java bridge over JNI for some C language interfaces on Windows. I have manual COM interfaces and a .lib that is used when building a JNI DLL.
The tricky part with WMI is that you want to use the standard COM APIs to create COM objects, whereas I created my own "factory" code as it was all proprietary.
You can download a snapshot of my development tree for ODMJNI 1.0 0.50beta Function-Complete Release . If you look at info.odma.odmjni100 in the development tree, you can see how the JNI DLL is built (using VC ++ 2005 Express Edition) and Java 1.5. The OdmJniBind.java class consists of static methods that are used in Java classes to coordinate object life cycles between Java classes and COM object interfaces. (The one-time peer tree section provides the implementation of OdmNative100.lib that is used when compiling odmjni100.dll, which is used through JNI.
source to share
@ z0ltan
You can write your code in C, but you need to save the file as CPP. As mentioned earlier, for DCOM support your file must be a CPP file.
@Umi For Java Integration - Compile your WMI code in C / CPP as a DLL (with the appropriate JNI header files) and then you will have to load the DLL file. Once this is done, you can access the WMI methods in the DLL files like a Java method call.
source to share