com.jacob.com.LibraryLoader.getPreferredDLLName()

Here are the examples of the java api com.jacob.com.LibraryLoader.getPreferredDLLName() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : DLLFromJARClassLoader.java
with GNU Lesser General Public License v2.1
from freemansoft

/**
 * Load the DLL from the clreplacedpath rather than from the java path. This code
 * uses this clreplaced's clreplaced loader to find the dell in one of the jar files
 * in this clreplaced's clreplaced path. It then writes the file as a temp file and
 * calls Load() on the temp file. The temporary file is marked to be deleted
 * on exit so the dll is deleted from the system when the application exits.
 * <p>
 * Derived from ample code found in Sun's java forums <p.
 *
 * @return true if the native library has loaded, false if there was a
 *         problem.
 */
public boolean loadLibrary() {
    try {
        // this replacedumes that the dll is in the root dir of the signed
        // jws jar file for this application.
        // 
        // Starting in 1.14M6, the dll is named by platform and architecture
        // so the best thing to do is to ask the LibraryLoader what name we
        // expect.
        // this code might be different if you customize the name of
        // the jacob dll to match some custom naming convention
        InputStream inputStream = getClreplaced().getResource("/" + LibraryLoader.getPreferredDLLName() + ".dll").openStream();
        // Put the DLL somewhere we can find it with a name Jacob expects
        File temporaryDll = File.createTempFile(LibraryLoader.getPreferredDLLName(), ".dll");
        FileOutputStream outputStream = new FileOutputStream(temporaryDll);
        byte[] array = new byte[8192];
        for (int i = inputStream.read(array); i != -1; i = inputStream.read(array)) {
            outputStream.write(array, 0, i);
        }
        outputStream.close();
        temporaryDll.deleteOnExit();
        // Ask LibraryLoader to load the dll for us based on the path we
        // set
        System.setProperty(LibraryLoader.JACOB_DLL_PATH, temporaryDll.getPath());
        LibraryLoader.loadJacobLibrary();
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}