Microsoft.Z3.dll is described in the file properties as the Z3 Managed DLL.
Java can load dlls. It does so using System.loadLibrary, or System.load, depending on the programmers preference.
If the Java designer also creates the DLL, javah can be used to define the import/export declarations. Unfortunately, that’s not my case. The DLL is already created by Microsoft as a Managed C# DLL.
I need some help taking a C# declaration such as the one found at Microsoft RISE Z3 managed API and prototyping a Java package/class to enable the call to succeed. (I am confident that the DLL is loaded).
To make it easier, the specific call is defined by Microsoft at line 03042 of Microsoft.Z3.h. Any sample code would be greatly appreciated!
The error I am getting from my server is:
java.lang.UnsatisfiedLinkError: Microsoft.Z3.GetVersion(
LMicrosoft/Z3$IntPtr;
LMicrosoft/Z3$IntPtr;
LMicrosoft/Z3$IntPtr;
LMicrosoft/Z3$IntPtr;)V
at Microsoft.Z3.GetVersion(Native Method)
at Microsoft.Z3.z3VersionString(Z3.java:81)
at DatabaseXml.XmlTest(DatabaseXml.java:66)
at DatabaseXml.doGet(DatabaseXml.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I had hoped that the managed version of the DLL would have some native compatibility with Java. It doesn’t appear so. So, the answer is to generate a new DLL that implements a JNI-compatible calling protocol as described in Sheng Liang’s “The Java™ Native Interface:Programmer’s Guide and Specification”. Some useful tutorials were found on David Caldwell’s website: InOnIt
Most of the C source code was extracted from Scala^Z3 and the final version is:
The header files come from multiple sources: jni.h and its dependencies come with the JDK and reside in its include and include\win32 directories. z3.h and z3_api come from Microsoft RISE Z3 and are installed to C:\Program Files (x86)\Microsoft Research\Z3-3.2\include. Microsoft RISE also provides z3.lib which resides in C:\Program Files (x86)\Microsoft Research\Z3-3.2\bin; you will need to link this with the above code into a Win32 DLL project called Z3GetVersion_Release.dll.
HelloWorld.h is generated by javah (see InOnIt for the example). To generate HelloWorld.h, you need the following Java class in a file named HelloWorld.java.
The sample code assumes you have copied all dlls from C:\Program Files (x86)\Microsoft Research\Z3-3.2\bin to your working directory, and you have pointed java.exe to the correct classpath where your compiled java classes are located. If all goes well, running the command “java example.jni.HelloWorld” will output the response: Z3 3.2 (build 0, rev. 0)