在 Windows (XP/2003) 上用 C/C++ 创建 ZIP 文件 [英] Creating a ZIP file on Windows (XP/2003) in C/C++

查看:28
本文介绍了在 Windows (XP/2003) 上用 C/C++ 创建 ZIP 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从 Windows C/C++ API 中的文件夹创建 ZIP 文件的方法.我可以找到使用 Shell32.Application CopyHere 方法在 VBScript 中执行此操作的方法,并且我找到了一个教程,解释了如何在 C# 中执行此操作,但对 C API 没有任何帮助(C++ 也很好,项目已经使用 MFC).

I am looking for a way to create a ZIP file from a folder in Windows C/C++ APIs. I can find the way to do this in VBScript using the Shell32.Application CopyHere method, and I found a tutorial explaining how to do it in C# also, but nothing for the C API (C++ is fine too, project already uses MFC).

如果有人可以分享一些可以在 Windows XP/2003 上成功创建 zip 文件的示例 C 代码,我将不胜感激.否则,如果有人能找到可靠的文档或教程,那就太好了,因为 MSDN 搜索不会出现太多.我真的希望避免为此发布第三方库,因为功能显然就在那里,我只是不知道如何访问它.谷歌搜索没有发现任何有用的信息,只是诱人的零碎信息.希望社区中有人解决了这个问题,并可以分享给后代!

I'd be really grateful if anyone can share some sample C code that can successfully create a zip file on Windows XP/2003. Failing that, if someone can find solid docs or a tutorial that would be great, since MSDN searches don't turn up much. I'm really hoping to avoid having to ship a third-party lib for this, because the functionality is obviously there, I just can't figure out how to access it. Google searches turn up nothing useful, just tantalizing bits and pieces of information. Here's hoping someone in the community has sorted this out and can share it for posterity!

推荐答案

这个答案很旧,但我不能删除它,因为它被接受了.看下一个

This answer is old, but I cannot delete it because it was accepted. See the next one

https://stackoverflow.com/a/121720/3937

----- 原答案-----

----- ORIGINAL ANSWER -----

这里有示例代码可以做到这一点

There is sample code to do that here

http://www.eggheadcafe.com/software/aspnet/31056644/using-shfileoperation-to.aspx

请务必阅读有关如何处理线程的监控以完成的内容.

Make sure you read about how to handle monitoring for the thread to complete.

根据评论,此代码仅适用于现有的 zip 文件,但 @Simon 提供了此代码以创建一个空白的 zip 文件

From the comments, this code only works on existing zip file, but @Simon provided this code to create a blank zip file

FILE* f = fopen("path", "wb");
fwrite("x50x4Bx05x06", 22, 1, f);
fclose(f);

这篇关于在 Windows (XP/2003) 上用 C/C++ 创建 ZIP 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆