Recently due to the special requirements of the project, we must call the Windows DLL in the program. We started with JNI, and later because there were too many DLLs to call, and very cumbersome. So we decided to use the open source Jawin call. Jawin can invoke a method in a DLL, or invoke a method in COM. Internally also provides a tool for directly exporting COM components to Java classes, which is personally considered convenient. Here is a test we made and passed it smoothly. 1, download jawin:http://jawinproject.sourceforge.net/. 2, configuration: "Will Jawin.jar placed in the%java_home%/jre/lib/ext." "Put the Jawin.dll under the C:/winnt/system32. Otherwise, an error occurs: Comexception:no Jawin in Java.library.path, or Jawin.dll in each project directory.
The example of debugging Jawin/njawin in EditPlus can be passed. And in eclipse, there are times when the above error occurs: Comexception:no Jawin in Java.library.path. "In Eclipse, the menu->window->preference->java->installed jres the original remove and builds a point to your Java SDK directory. "OK." 3, the program test:
"The way to call Dll,dll does not need to be exported, direct call on it, the following is a download of the package provides an example:" I Win2000 under the test pass. * * Created on DEC, * */import ORG.JAWIN.FUNCPTR;
Import Org.jawin.ReturnFlags;
/** * @author GF Mail to gf@163.com * "TODO to" the template for this generated type comment go to * Window- Preferences-java-code Style-code Templates */public class Gfjawintest {
public static void Main (string[] args) {
try {
Funcptr MsgBox = new Funcptr ("USER32. DLL "," MessageBoxW ");
Msgbox.invoke_i (0, "Hello from-a DLL", "from Jawin", 0, Returnflags.check_none);
catch (Exception e) {
E.printstacktrace ();
}
}
}