The Code Project View our sponsorsClick here for Dundas Software's TCP/IP Development KitAdvertise on the CodeProject
Home >> Files & Folders >> General

Creating a Self Extracting Executable
By James Spibey

A class that allows you to create self extracting executables for use in distribution or setup programs 
 VC5 SP3, NT4 SP4
 Posted 22 Nov 1999
 Updated 25 May 2000
Articles by this author
Send to a friend
Printer friendly version
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
22 users have rated this article. result:
4.5 out of 5.

  • Download demo project - 48 Kb
  • Self Extractor Builder

    Introduction

    This class allows you to create self extracting executables for use in distribution or setup programs. Many people have helped me along the way to produce this class but here are a couple I would like to thank.

    Please note that this class does not contain any compression algorithms so the resulting executable with be the size of the sum of it's parts. The class could easily be extended to add compression in the future if anyone wishes.

    Description of the Self-Extracting (SFX) executable

    The SFX file which this class creates consists of an extraction executable with the data files appended to the end of it. The data on the end of the file does not affect the executable image and so the file executes as if the data wasn't even there. So to extract the data, the executable must first detach the data from itself and then create the approriate files. The way I have chosen to do this is to write a 'Table of Contents' (TOC) after the data which can be read by the extractor to find out where the various files are stored in the data segment.

    File Layout

    The layout of the TOC is as follows:-

    Starting from the end of the archive and working backwards :

    Header Info

    Table of Contents

    This section contains one record in the following format for each file

    Data Segment

    Each file is written (uncompressed) here in the order of the TOC

    After this is the extractor executable.

    How To Use it

    Having said all that, you don't need to know any of that stuff above to use it. All you need to do is create an instance of CSelfExtractor and then call AddFile() to add in all the files that you want to include. Next call Create() to create the archive.

    The demo project consists of two projects - 'Extractor' which is the executable which extracts the archive and Self Extractor which is the program for building Self Extracting archives. Self Extractor allows you to specify an external extractor program to use for the archive or alternatively you can use the extractor which has been compiled into the program inside the resources. Read the source code to find out more.

    As always, expect bugs. Don't shout if you can't get it to work. The demos are just as they sound - demos. They are not fully implemented and fully tested release software, they are an example of how the classes should be used. The demos make use of classes written by other people at codeguru so any bugs in those should be directed at their respective authors.

    About James Spibey

    James is currently working as a Software Engineer for Siemens Airport Solutions, integrating IT systems into the world's airports. He has been programming in C/C++ for 5 years and Visual C++/MFC for 3 years, although most of his recent work has been in ASP and COM+.

    His software company, Lyme Software, has a web site at http://www.lymesoft.co.uk.

    James is originally from Nottingham (no Robin Hood jokes please) but is now based in sunny Manchester, UK.

    Click here to visit James Spibey's homepage.

    [Top] Sign in to vote for this article:     PoorExcellent  
    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 8 of 8 (Total: 8)First Prev Next Last
    Subject 
    Author 
    Date 
      Internal Error
    Florian 14:39 12 Oct 00 
      Re: Internal Error
    James Spibey 7:36 18 Oct 00 
      Re: Internal Error
    Colin J Davies 17:51 31 Jan 01 
      Re: Internal Error
    James Spibey 3:27 1 Feb 01 
      Report Error
    Jeff Chin 23:03 14 Sep 00 
      File Open permissions
    Brian Collison 16:23 19 Apr 00 
      Compiler Errors
    chris 17:20 22 Feb 00 
      Re: Compiler Errors
    Mark B. Elrod 14:55 24 Aug 00 
    Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

    Home >> Files & Folders >> General
    last updated 25 May 2000
    Article content copyright James Spibey, 1999
    everything else © CodeProject, 1999-2001.
    The Code Project View our sponsorsGet the power of C++ with the ease of VBAdvertise on the CodeProject