C# 我无法使SevenZipLib库工作(p/invoke)
非常基本的c#知识,是我第一次使用任何与p/invoke相关的东西 请帮助我,我已经做了这个代码,但它似乎不工作C# 我无法使SevenZipLib库工作(p/invoke),c#,C#,非常基本的c#知识,是我第一次使用任何与p/invoke相关的东西 请帮助我,我已经做了这个代码,但它似乎不工作 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using S
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[DllImport("C:\\Users\\lchris\\Desktop\\SevenZipLib_9.13.2\\SevenZipLib\\SevenZipLib\\7z86.dll")]
public static extern void SevenZipArchive(string c);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SevenZipArchive archive = new SevenZipArchive("file.rar"))
{
foreach (ArchiveEntry entry in archive)
{
Console.WriteLine(entry.FileName);
}
}
}
}
}
它告诉我SevenZipArchive是一个“方法”,并且像“类型”一样被使用
我已经在我的项目中加入了这个库,我只是不知道如何使用它
这是图书馆:
您首先需要删除此代码:
[DllImport("...")]
public static extern void SevenZipArchive(string c);
您不需要提供任何p/invoke声明。图书馆会帮你整理好的
这是一个.net程序集。你使用它就像你使用其他任何东西一样。采取以下步骤:
SevenZipLib\bin\Debug\SevenZipLib.dll
或SevenZipLib\bin\Release\SevenZipLib.dll
,具体取决于您选择的目标代码>到项目代码,以获得对命名空间的访问权
一旦你完成了,你的代码就可以工作了。您可以使用下载中提供的测试项目作为丰富的示例代码源。是7-Zip的管理器包装,为您处理p/Invoke调用。@Douglas也是如此SevenZipLib@DavidHeffernan你说得对。我假设它是OP的P/Invoke调用中的本机库。非常感谢,我现在明白了。它显示了一个新的错误,但是,我更新了我的评论,也许你可以帮助我。我恢复了编辑。那是另一个问题。但是,您没有告诉我们完整的错误消息,这没有帮助。您需要确保7z dll 7z64.dll和7z86.dll位于程序集SevenZipLib.dll旁边。这是完整的错误“找不到7-zip库”。但是我修复了它,我错误地引用了另一个文件夹。