Skip to main content

Visual Studio 2005 DLLS-

1 reply [Last post]
drdad5727
Offline
Joined: 2008-10-16
Points: 0

Has anyone solved the problem of distributing a nativelib that was built using VS2005?

The issue is that the target system may not have all the dependent, Microsoft supplied dlls. The solution recommended by MS is to run a special executable that will install them (vcredist_x??). My plan is to write an installer that copies that executable from the website and executes it. I'm just wondering if anyone has already solved this problem and would be willing to share it.

(I thought I'd seen a thread about this on this forum but I can't find it now.)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
drdad5727
Offline
Joined: 2008-10-16
Points: 0

Thought I'd answer this myself. The code to do this follows. Notes:

Some systems seem to be case sensitive. Be sure you have the right case when you do a load library.

Microsoft's vcredist has issues of it's own (the infamous 1732 error). This doesn't fix it.
-=-====-=-=-=-=-=-=-=-=-=-=-==-=-
package Installer;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import javax.jnlp.ExtensionInstallerService;
import javax.jnlp.ServiceManager;
import javax.jnlp.UnavailableServiceException;
import javax.swing.JOptionPane;
public class InstallMain {

public static void main (String[] args) {
ExtensionInstallerService eis = null;
try {
eis = (ExtensionInstallerService)ServiceManager.lookup("javax.jnlp.ExtensionInstallerService");
} catch (UnavailableServiceException e) {
JOptionPane.showMessageDialog(null, String.format("JNLP Failure: %s%n", e.getMessage()), "Installation Failure",
JOptionPane.ERROR_MESSAGE);
System.exit(-1);
}
eis.setStatus("Starting...");
int result = new InstallMain().doStuff();
eis.setStatus("Done.");
if (result == 0) eis.installSucceeded(false);
else eis.installFailed();
System.exit(result);
}
private final static String exNamePre = "vcredist_x86";
private final static String exNameSuffix = "exe";
private int doStuff () {
try {
InputStream is = getClass().getClassLoader().getResourceAsStream(exNamePre + "." + exNameSuffix);
File tempF = File.createTempFile(exNamePre, exNameSuffix);
byte[] buff = new byte[8192];
FileOutputStream fos = new FileOutputStream(tempF);
int rLeng = 0;
while ((rLeng = is.read(buff)) >= 0) {
fos.write(buff, 0, rLeng);
}
is.close();
fos.close();
Process proc = Runtime.getRuntime().exec(tempF.getAbsolutePath());
tempF.deleteOnExit();
return proc.waitFor();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, String.format("Installation failed due to %s: %s%n", e.getClass().getName(),
e.getMessage()), "Installation Failure", JOptionPane.ERROR_MESSAGE);
return -1;
}

}

}