我正在寻找一种从 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
当没有异常时,C++ 异常会以何种方式减慢代码速In what ways do C++ exceptions slow down code when there are no exceptions thown?(当没有异常时,C++ 异常会以何种方式减慢代码速度?)
为什么要捕获异常作为对 const 的引用?Why catch an exception as reference-to-const?(为什么要捕获异常作为对 const 的引用?)
我应该何时以及如何使用异常处理?When and how should I use exception handling?(我应该何时以及如何使用异常处理?)
C++中异常对象的范围Scope of exception object in C++(C++中异常对象的范围)
从构造函数的初始化列表中捕获异常Catching exceptions from a constructor#39;s initializer list(从构造函数的初始化列表中捕获异常)
C++03 throw() 说明符 C++11 noexcept 之间的区别Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 说明符 C++11 noexcept 之间的区别)