jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes DLL's, dynamic linked library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "DLL Watch "DLL New topic

DLL's, dynamic linked library

Devin Crane
Ranch Hand

Joined: Aug 01, 2012
Posts: 32
I've made a game using Java in Eclipse that is supposed to use a coin dispenser as an automatic reward system. The coin dispenser came with 3 DLL's, but I can't get it to load the DLL's. This is the class I've created to load the DLL's, "CoinDispenserInterface.java":

package SubSearch;
/*import C:/Windows/System32/Coinco.MDB.dll;
import CoinDispenserInterface.dll;
import cai_mdb_w32d.dll;//*/

class CoinDispenserInterface

public native void inDll();

public static void main(String[] args)
System.out.println ("dispensing coin in interface");
//new CoinDispenserInterface().dispenseCoin();

System.out.println ("Loading DLLs");


System.loadLibrary("C://Documents and Settings//Devin//My Documents//Dropbox//" +
System.loadLibrary("C://Documents and Settings//Devin//My Documents//Dropbox//" +

System.out.println ("Loading complete");

When I use System.loadLibrary I get a java.lang.UnsatisfiedLinkError that says the cai_mdb_w32d.dll isn't in the java.library.path, which doesn't make sense b/c when I click on configure build path, it's listed there.

When I use System.load I get the same error with a different explanation: "This application has failed to start because the application configuration is incorrect." It suggests reinstalling the application.

I've tried storing the 3 DLL's in the C:/WINDOWS/System32 folder, but it didn't seem to help. Even if I were to get this to work, I don't understand how this class's main() is supposed to work with the main() my game already has.

Any help is greatly appreciated.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Well, first of all you don't import them into your source code. So "import X.dll" is not what you do (it doesn't do anything).

And second of all the API documentation for the loadLibrary() method says

Loads the dynamic library with the specified library name. A file containing native code is loaded from the local file system from a place where library files are conventionally obtained. The details of this process are implementation-dependent. The mapping from a library name to a specific filename is done in a system-specific manner.

In other words you don't pass a path to that method. You pass just the name of the library and put the actual DLL in the right place. As the error message says, that's the "java.library.path" which you appear to have assumed is the same as the build path of your Eclipse project. (Hint: bad assumption. Check the value of the system property by that name.)

(Also this isn't a question about Servlets so I'm going to move it.)
Devin Crane
Ranch Hand

Joined: Aug 01, 2012
Posts: 32
Thanks for the tips. They helped. The biggest thing I'd have never guessed was not including the path to it, or the '.dll' extension.

One more question, at least for now: running System.loadLibrary("cai_mdb_w32d"); produces the error now that 'This application has failed to start because the application configuration is incorrect.' I'm still researching what this means and how to fix it, but is anyone familiar with this error? Is it something I can fix or can only the company that provided me with the dll address the issue?

Don't get me started about those stupid light bulbs.
subject: DLL's, dynamic linked library
It's not a secret anymore!