在 Visual C 中使用 zlib CLR Windows 窗体应用程序

发布于 2024-12-05 12:59:03 字数 538 浏览 0 评论 0原文

我已经尝试这样做很长时间了,那就是让 zlib 库与我的程序一起使用。我将 Microsoft Visual C++ 2008 Express Edition 与 CLR Windows 窗体应用程序一起使用。问题是我担心 zlib 太旧而无法与我正在使用的东西一起使用。我找到的 zlib 的所有示例(极少数示例)都是 Win32 应用程序。

那是另一回事;我找不到任何未过时的 zlib 示例。我确实知道 zlib 已经过时了,但我找不到任何替代品:(

所以如果有人能首先告诉我是否可以在我的应用程序中使用 zlib 以及如何使用,非常感谢。如果有人想采取更进一步,也许可以推荐一个更好的类似 zlib 的程序,我可以使用,更感谢

(顺便说一句,我正在创建一个应用程序来读取游戏《我的世界》的关卡数据。可以在 上找到一些信息。那个此处。)

I've been trying to do this for a long time, and that is to get the zlib library to work with my program. I'm using Microsoft Visual C++ 2008 Express Edition with a CLR Windows Forms Application. The thing is I'm worried that zlib is to old to work with what I'm using. All the examples (the very few examples) of zlib I find are with a Win32 application.

And that's the other thing; I can't find any zlib examples that aren't outdated. And I do understand that zlib is old, but I can't find any alternatives :(

So if anyone could first of all tell me if its possible to use zlib with my application, and how, thanks a bunch. If someone wants to take it a step further and maybe recommend a better zlib-like program that I can use, thanks even more.

(And by the way, I'm creating an application to read the level data of the game Minecraft. A little can be found on that here.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨巷深深 2024-12-12 12:59:03

这不是问题,C++/CLI 就是为了处理这样的任务而设计的。您必须告诉编译器 zlib 头不是由 #pragma 管理的托管代码,并告诉链接器链接导入库。像这样,在示例控制台模式应用程序中:

#include "stdafx.h"
#pragma managed(push, off)
#include "c:/temp/deleteme/include/zlib.h"
#pragma managed(pop)
#pragma comment(lib, "c:/temp/deleteme/lib/zdll.lib")


using namespace System;

int main(array<System::String ^> ^args)
{
    const char* vers = zlibVersion();
    String^ mvers = System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)(void*)vers);
    Console::WriteLine(mvers);
    Console::ReadKey();
    return 0;
}

您唯一需要做的就是将 DLL 复制到构建目录中,以便您可以调试代码。项目 + 属性、构建事件、构建后事件、命令行:

 xcopy /d "c:\temp\deleteme\zlib1.dll" "$(TargetDir)"

也许您想选择不同的安装目录:)

It is not a problem, C++/CLI was made to handle tasks like this. You have to tell the compiler that the zlib header isn't managed code with #pragma managed and tell the linker to link the import library. Like this, in a sample console mode app:

#include "stdafx.h"
#pragma managed(push, off)
#include "c:/temp/deleteme/include/zlib.h"
#pragma managed(pop)
#pragma comment(lib, "c:/temp/deleteme/lib/zdll.lib")


using namespace System;

int main(array<System::String ^> ^args)
{
    const char* vers = zlibVersion();
    String^ mvers = System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)(void*)vers);
    Console::WriteLine(mvers);
    Console::ReadKey();
    return 0;
}

Only other thing you have to do is to get the DLL copied into the build directory so you can debug the code. Project + Properties, Build Events, Post-Build Event, Command line:

 xcopy /d "c:\temp\deleteme\zlib1.dll" "$(TargetDir)"

Maybe you want to pick a different install directory :)

千纸鹤带着心事 2024-12-12 12:59:03

我在多个 C++/CLI 应用程序中使用了 DotNetZip 库。它非常容易上手,而且我还没有发现任何它不能做的事情(压缩、解压缩、受密码保护的 zip 文件都运行良好)。从描述来看,它是对 ZLib 的改进:

如果您想要一个更好的 DeflateStream 或 GZipStream 类来替换 .NET BCL 中内置的类,DotNetZip 也有。 DotNetZip 的 DeflateStream 和 GZipStream 可在基于 Zlib 的 .NET 端口的独立程序集中使用。这些流支持压缩级别并提供比内置类更好的性能。还有一个 ZlibStream 来完成该设置(RFC 1950、1951、1952)。

I've used the DotNetZip library in several C++/CLI applications. It's very easy to get going and I've yet to find anything it can't do (zipping, unzipping, password protected zip files all works well). From the description, it's an improvement over ZLib:

If all you want is a better DeflateStream or GZipStream class to replace the one that is built-into the .NET BCL, DotNetZip has that, too. DotNetZip's DeflateStream and GZipStream are available in a standalone assembly, based on a .NET port of Zlib. These streams support compression levels and deliver much better performance than the built-in classes. There is also a ZlibStream to complete the set (RFC 1950, 1951, 1952).

亢潮 2024-12-12 12:59:03

如果您使用 CLR,您不能使用内置的 .NET gzip 库吗?
http://msdn.microsoft.com/en-us /library/system.io.compression.gzipstream.aspx

If you're using CLR, can't you use the built in .NET gzip library?
http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文