0

I want to compress/uncompress a single file in my C++ application without using an external library. I have read that Cabinet Files can be used to do this, but I am unable to find any useful examples.

I am not even sure if Cabinet Files can still be used in modern Windows versions, can anyone provide a simple example to do so.

Tom
  • 1,344
  • 9
  • 27
  • See [File Compression and Decompression](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364219.aspx). CAB-files are still supported, because there is no replacement to compress files built into Windows (or at least exposed as an API). – IInspectable Jan 10 '16 at 05:45
  • Not sure why you would not want to use zlib for instance. What's wrong with libraries? – David Heffernan Jan 10 '16 at 09:32
  • @David Heffernan What I mean is if Windows API provides this functionality, then why would I use a library. – Tom Jan 10 '16 at 10:36
  • To get better compression – David Heffernan Jan 10 '16 at 10:38
  • @David Heffernan Good point! but in my case I only want a "normal" compression (the one that you get with the default settings for WinZip/WinRAR), which I've read that Cabinet Files provide. – Tom Jan 10 '16 at 10:44
  • I don't know where you read that, but it isn't true. There's no such thing as "normal" compression. There are lots of different algos. ZIP is a container format that can use different algos. Likewise MS cabinet. – David Heffernan Jan 10 '16 at 10:54
  • @David Heffernan I assumed that the **LZX** compression algorithm (which Cabinet Files support) provides a "normal" compression ratio. – Tom Jan 10 '16 at 11:02

1 Answers1

3

They still work (Windows 2000 - Windows 10, at least).

See MSDN for the API Documentation and samples of how to decompress a file or create a new cabinet.

Example implementations for the callbacks are available on their respective pages. Ex: fnMemFree and fnNotify.

Mitch
  • 21,223
  • 6
  • 63
  • 86
  • Is there a separate SDK for Cabinet Files that I should install? because some header files used in the examples are not found. I am using Visual C++ 2010. – Tom Jan 10 '16 at 05:55
  • No. Just `fdi.h`. You do have to implement the callbacks yourself, as it looks like those are not included in the sample, but they are mostly trivial. – Mitch Jan 10 '16 at 06:37
  • On review, it looks like the callbacks are available, they are just on their own pages. I added links to the answer. – Mitch Jan 10 '16 at 06:44
  • 1
    What's missing from the documentation, though, is the calling convention. The Cabinet API uses `__cdecl`. So as a shortcut you could pass `free` or `malloc` directly to `FCICreate`, instead of implementing your own wrappers. – IInspectable Jan 10 '16 at 07:54