Click here to Skip to main content
13,350,708 members (72,968 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 25 Jun 2000

Self-Extracting File Framework

, 7 May 2001
Rate this:
Please Sign up or sign in to vote.
An article about creating Self-Extracting files with integrated compression


This article is about making self-extracting files (lets call them "sfx"), or more precisely, making the framework for creating sfx.

For a start, let's look at the physical anatomy of a sfx:




User Data

As you can see, there is an executable (sfxLoader.exe) with some appended data.


This is the soul of a sfx, a regular Win32 portable executable file that has the responsibility of managing a compressed start module.

For making this I established some goals:

Small footprint: The goal was to make the small possible sfxLoader, and the end the result was a sfxLoader of about 20 KB. This is in part because of some techniques demonstrated in other articles, namely:

I have also made a stub. If you want more information on this, start your reading with the file LoaderPriv.h.

Compression: The compression has left in charge with the well-known zlib.


A StartModule is a piece of software that can be either an executable (EXE) or a dynamic link library (DLL). The StartModule has the responsibility of managing the User Data, for example this can be a setup program.

User Data

Here you can put any data that makes sense to the StartModule, since the StartModule will process this data.


This structure contains, among other things, the size and offset of the start module. You should look at the source code for more details.

The Framework

The framework for creating sfx consists mostly in the class CSFXFileCreator.

The steps for creating a sfx are:

  1. Create your own class derived from CSFXFileCreator and override the AppendStartModule and AppendUserData.
  2. Call CSFXFileCreator::Create.
  3. Call CSFXFileCreator::Close.

You can find the interface of this in the header sfx.h. Also, there are some helper functions and classes in the header sfx_helpers.h. For a real example, take a look at the sample project Compress.

Installing and Building

  1. Download and extract the code from this article to 'c:\sfx'
  2. Download and extract the ZLib to the directory 'c:\sfx\ZLib'
  3. Open and Build the following projects from the Loader workspace ('c:\sfx\Loader\Loader.dsw'):
    • Loader
    • StartModule
    • Compress
    At the end, you will get in the bin directory ('c:\sfx\bin') the files, sfxLoader.e32, StartModule.dll and Compress.exe
    NOTE1: You will get some 'LINK : warning LNK4078: multiple ".data" ....', just ignore them.
    NOTE2: If you want to build a EXE start module you have to define '_STARTMODULE_IS_EXE' in the Loader.h file, and rebuild all projects in workspace.
  4. Run the 'c:\sfx\bin\Compress.exe' and you will get a sample sfx file called MySFXFile.exe in the directory 'c:\sfx\bin'


  1. You must mention my name in your application documentation/help box, something like, Portions © 2000 by Rui Godinho Lopes <>.
  2. I would appreciate an email letting me know that you are using this code.
  3. I cannot be held responsible of any kind of data lost caused directly or indirectly by the use of this code. Use it at your own risk.
  4. You cannot sell this code. This is free software.
  5. If you use this code in a commercial application, you have to give me a copy of your product.

Don't forget, if you have constructive thoughts just email me! Rui Godinho Lopes


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Rui Lopes
Web Developer
Portugal Portugal
No Biography provided

You may also be interested in...


Comments and Discussions

Praisethank you Pin
steppeman10-Feb-16 8:18
membersteppeman10-Feb-16 8:18 
GeneralAppending files Pin
kementeus26-Nov-06 19:24
memberkementeus26-Nov-06 19:24 
GeneralVC++ 2005 and zlib-1.2.3 problems Pin
Prof. Nimnul20-Jul-06 4:57
memberProf. Nimnul20-Jul-06 4:57 
GeneralRe: VC++ 2005 and zlib-1.2.3 problems Pin
kementeus24-Nov-06 15:05
memberkementeus24-Nov-06 15:05 
GeneralRe: VC++ 2005 and zlib-1.2.3 problems Pin
Prof. Nimnul25-Nov-06 4:24
memberProf. Nimnul25-Nov-06 4:24 
GeneralZLib source Pin
BobDonjacour4-Mar-05 5:58
memberBobDonjacour4-Mar-05 5:58 
GeneralRe: ZLib source Pin
BobDonjacour4-Mar-05 6:14
memberBobDonjacour4-Mar-05 6:14 
GeneralRe: ZLib source Pin
Prof. Nimnul20-Jul-06 5:02
memberProf. Nimnul20-Jul-06 5:02 
Questionextract to memory? Pin
Rogerio Silva20-Apr-04 18:14
memberRogerio Silva20-Apr-04 18:14 
Generalself extracting exe Pin
Mandan Misra16-Jun-03 1:02
memberMandan Misra16-Jun-03 1:02 
GeneralRe: self extracting exe Pin
Rui Godinho Lopes16-Jun-03 3:54
memberRui Godinho Lopes16-Jun-03 3:54 
Questionappend user data....? Pin
prgmaker13-Jan-02 7:41
memberprgmaker13-Jan-02 7:41 
QuestionDLLs ? Pin
Anonymous8-May-01 2:55
memberAnonymous8-May-01 2:55 
AnswerRe: DLLs ? Pin
Rui Lopes17-Jun-01 12:10
memberRui Lopes17-Jun-01 12:10 
GeneralCool Pin
[ MoD ]11-Jul-00 6:55
suss[ MoD ]11-Jul-00 6:55 
that heled me to understand sfx files... thank yo

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 8 May 2001
Article Copyright 2000 by Rui Lopes
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid