You are here:

C++/self extracting executable


QUESTION: I'm trying to write a program that will generate self extracting exe's given a zip file

ANSWER: I don't fully understand the goals of the program.  A self extracting EXE contains a Zip of an EXE which it expands and executes.  But this is a self-extracting EXE given an EXE.  What is in the given ZIP file you mention?


---------- FOLLOW-UP ----------

QUESTION: The program that I'm trying to write has to generate an exe which contains a zip file. If the exe is run it should extract the zip file to the current directory.

Assuming Windows, since you didn't specify, I would do the following:

Use a compression algorithm that a Windows API function will decompress.  (See the Window API help.)  Or, simply include code to decompress using the same algorithm you'll use to compress. The advantage of using Windows is you may be able to decompress a memory image to a file.  If you don't care about creating a temporary file, you can create a temporary file and unzip that file to a new file.

Storing the ZIP in the EXE is easy in windows.  Add it as a resource to the EXE.  See the help file on user-defined resources.

When the program is run, load the resource (in your case you'd probably create a file) from the data being loaded, use the decompress function you included in the EXE to decompress the Zip to an Exe file.  Delete the temporary ZIP file.  Run the EXE (you can use spawn I believe), and terminate the EXE.  If you also want to delete the EXE that unzipped the file, you have to lookup up how to schedule a delete (using the Windows API, not the Windows scheduler).  Windows will watch for the file not being used and will delete it for you.



All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2016 All rights reserved.