How to Create a JNI with Visual Studio 6

Visual Studio 6 is the ideal environment for building JNIs on Windows because the resultant DLLs have virtually no dependencies! You can't really say the same thing with later versions of Visual Studio which introduce dependencies on the .NET framework (e.g. MSVCP71.DLL and MSVCR71.DLL) and Side-by-side (SxS) assemblies.

In this tutorial, I will outline the the steps I took to compile and build a 32 bit JNI for Windows using Visual Studio 6. I have posted instructions for how to compile a 64 bit application here.

Step 1: Create a New Visual Studio Project

Open Visual Studio and go to File->New... In the Project tab, select "Win32 Dynamic-Link Library" and
specify project name/path:

Step 2: Add Java Includes

Add path to jdk/include and jdk/include/win32.
Settings -> C/C++ -> Category -> Preprocessor -> "Additional include directories"

Step 3: Disable Precompiled Headers

Do not use Precompiled Headers:
Settings -> C/C++ -> Category -> Precompiled Headers -> Select "Not using precompiled headers"

Step 4: Create a Java class with "native" methods

Step 5: Create a .h file using javah

Step 6: Add the .h file to your project and create a .cpp file

Next step is to implement the "native" JNI methods.

Step 7: Compile and Build the DLL

Step 8: Implement Java-Side Code


Runtime Errors

  • Can't load IA 32-bit .dll on a AMD 64-bit platform
    • If you see this error, it probably means that your JRE/JDK is 64 bit and you're trying to load a 32 bit DLL. You will need to recompile your DLL using a 64 bit compiler. I have posted instructions for Visual Studio here.