I'm creating an application in C# using Visual Studio 2010/.NET 4.0. For part of the application I need to zip the files and make use of the J# library. I'm having an issue importing kernal32.dll. I've tried setting the import value to "kernal32", "kernal32.dll" and the absolute path in the system32 folder. The error I get is below and the relevant source code is below that. The error occurs at the line where I invoke "LoadLibrary(fullPath);" Any help would be greatly excavated!
I pulled some of this code from an example at http://blogs.windwardreports.com/davidt/2011/02/calling-j-code-from-net-40.html
System.DllNotFoundException was unhandled Message=Unable to load DLL 'kernal32': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Source=ZipLibrary TypeName="" StackTrace: at ZipLibrary.Zipper.LoadLibrary(String ipFileName) at ZipLibrary.Zipper..ctor(String directoryToZip, String zipToPath) in c:\users\cchamberlain\documents\visual studio 2010\Projects\AppDeploy\ZipLibrary\Zipper.cs:line 37 at AppDeployLibrary.AppDeployer.Deploy() in c:\users\cchamberlain\documents\visual studio 2010\Projects\AppDeploy\AppDeployLibrary\AppDeployer.cs:line 37 at AppDeploy.Program.Main(String[] args) in c:\users\cchamberlain\documents\visual studio 2010\Projects\AppDeploy\AppDeploy\Program.cs:line 21 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
public class Zipper
{
private const string DotNetFrameworkRelativePath = @"..\Microsoft.NET\Framework\v2.0.50727";
private const string VjsDllName = "vjsnativ.dll";
[DllImport("kernal32", SetLastError=true)]
static extern IntPtr LoadLibrary(string ipFileName);
private readonly string _directoryToZip;
private readonly string _zipToPath;
public Zipper(string directoryToZip, string zipToPath)
{
// If the current framework is .NET 4, include the VJS dll.)))
if(Environment.Version.Major >= 4)
{
string folder = SystemIO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), DotNetFrameworkRelativePath);
folder = SystemIO.Path.GetFullPath(folder);
string fullPath = SystemIO.Path.Combine(folder, VjsDllName);
// Check to see if file exists, if not the J# redistributable is not installed.
if(!SystemIO.File.Exists(fullPath))
{
throw new ApplicationException("ERROR: Zipper requires that the Microsoft Visual J#® 2.0 Redistributable Package be installed on the environment.");
}
LoadLibrary(fullPath);
}
_directoryToZip = directoryToZip;
_zipToPath = _zipToPath;
}
}