试图从C#(.NET4.0)加载kernal32和J#库并获得kernal32加载错误

试图从C#(.NET4.0)加载kernal32和J#库并获得kernal32加载错误,c#,.net,dllimport,C#,.net,Dllimport,我正在使用Visual Studio 2010/.NET 4.0在C#中创建一个应用程序。对于应用程序的一部分,我需要压缩文件并利用J#库。我在导入kernal32.dll时遇到问题。我已经尝试将导入值设置为“kernal32”、“kernal32.dll”以及system32文件夹中的绝对路径。下面是我得到的错误和相关的源代码。错误发生在我调用“LoadLibrary(fullPath);”的行中,任何帮助都将被极大地挖掘 我从网站上的一个示例中提取了一些代码 System.DllNotFou

我正在使用Visual Studio 2010/.NET 4.0在C#中创建一个应用程序。对于应用程序的一部分,我需要压缩文件并利用J#库。我在导入kernal32.dll时遇到问题。我已经尝试将导入值设置为“kernal32”、“kernal32.dll”以及system32文件夹中的绝对路径。下面是我得到的错误和相关的源代码。错误发生在我调用“LoadLibrary(fullPath);”的行中,任何帮助都将被极大地挖掘

我从网站上的一个示例中提取了一些代码

System.DllNotFoundException未处理 Message=无法加载DLL“kernal32”:找不到指定的模块。(来自HRESULT的异常:0x8007007E) 来源=ZipLibrary TypeName=“” 堆栈跟踪: 位于ZipLibrary.zippers.LoadLibrary(字符串ipFileName) 在c:\users\cchamberlain\documents\visualstudio 2010\Projects\AppDeploy\ZipLibrary\Zipper.cs中的ZipLibrary.Zipper..ctor(字符串directoryToZip,字符串zipToPath)处:第37行 在c:\users\cchamberlain\documents\visualstudio 2010\Projects\AppDeploy\AppDeployLibrary\AppDeployer.cs中的AppDeployer.AppDeployer()处:第37行 在c:\users\cchamberlain\documents\visualstudio 2010\Projects\AppDeploy\AppDeploy\Program.cs中的AppDeploy.Program.Main(字符串[]args)处:第21行 位于System.AppDomain.\u nExecuteAssembly(RuntimeAssembly程序集,字符串[]args) 位于System.AppDomain.ExecuteAssembly(字符串汇编文件、证据汇编安全性、字符串[]args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()上 位于System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态) 位于System.Threading.ThreadHelper.ThreadStart()处 内部异常:


试试内核32。通过P/Invoke页面查看下面的示例

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;
    }
}
[DllImport("kernel32", SetLastError=true)]
static extern IntPtr LoadLibrary(string lpFileName);