Jay Jay - 11 days ago 8
C++ Question

Creating a ZIP file on Windows (XP/2003) in C/C++

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).

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!

Answer

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

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

----- ORIGIN ANSWER -----

There is sample code to do that here

[EDIT: Link is now broken]

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.

Edit: 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("\x80\x75\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 22, 1, f); fclose(f);
Comments