DLL from Java with Jawin
Do you need to use a Windows DLL from Java? I recommend investigating the open source tool: Jawin. I found used this tool in order to call a DLL that converts HTML to RTF. After struggling with various JNI tutorials, Jawin was refreshing. What makes this tool outstanding is the jawinBrowser. Here’s a tutorial on calling a DLL from Java:
1. Download Jawin
2. In a command prompt, go to the typebrowser/ directory
3. java -jar jawinBrowser.jar
This will start the jawinBrowser that allows you to generate Java code to interact with the Windows DLL.
4. Start a new project and name it anything you wish
5. Next step is to point to the DLL - click the “New” button and select the DLL
6. Highlight the DLL and then double click the configuration options on the left hand side:

7. Change the java package name to something appropriate. In my example, I converted it to com.supergloo.htmlconvert.
8. Specify an output directory; e.lg /tmp or c:/temp
9. Click Ok.
10. From the menu bar, select Code Generation->Generate Full Code
11. Next, from the menu bar, select Code Generation-> Save Java Files
You now have java src files to call your DLL methods! (check the directory you specified in step 8).
Going further, you will have an IConverter class that you can call. In my case, I used the following:
public static String convert(String htmlString) throws COMException{ String rtfString = ""; //Initialize service COM objects Ole32.CoInitialize(); IConverter iconv = new IConverter("Html2Rtf.Converter");
//Set properties of coversions. See help for Sautin
iconv.setPreserveTables(true);
iconv.setPreserveNestedTables(true);
iconv.setPreserveTableWidth(true);
iconv.setPreserveImages(true);
iconv.setPreserveFontFace(true);
iconv.setPreserveFontColor(true);
iconv.setRtfLanguage(eLanguage.l_English);
//rtfString = iconv.Convert(htmlString, “”, “”);
rtfString = iconv.ConvertFileToString(htmlString, “”, “”);
//UnInitialize service COM objects
Ole32.CoUninitialize();
return rtfString;
}
To use in your Java project, make sure to include jawin.jar and jawin-Stubs.jar in your classpath.
You can drop the Jawin.dll in to %WINDOWS%\system32 or specifically set the PATH and library path when invoking your Java app; e.g. here’s a .bat file example:
set PATH=%PATH%;.\dll set CLASSPATH=.\bin;.\lib\jawin.jar;.\lib\jawin-stubs.jar java -Djava.library.path=.\dll Test




