ExeCreator Utility


Environment: VC6

ExeCreator is a small utility to enwrap any number of files into a single exe. This new enwrapped exe when executed spits all the files to a desired folder.

It consists of two applications: ExeCreator and ExeExtractor.

It is the main application which provides GUI for receiving file names to be added, creates a new ExeExtractor.exe from one present in its resources, and adds all the files as resources to this new ExeExtractor.exe. It uses UpdateResource() to dynamically add files (converted to specified format known to ExeExtractor.exe) into resource in Extractor.exe.

It extracts the files added as resource by ExeCreator into a folder.

In next version of this program I'll try to add compression in file data stored and an encryption option. But presently also it provides a useful tool for self-extracting exe's especially used in installations.

// Create a buffer which will be added as resource to 
// the ExeExtractor exe
// First byte in buffer is set to number of files in list
LPSTR buff = (LPSTR)new DWORD(m_InList.GetCount());
UINT nSize = sizeof(DWORD);
// Add each file
for(DWORD i = 0;i < *(DWORD *)buff;++i)
  CString inFName;

  // Open i file 
  FILE* fpIn = fopen(inFName,"rb");
  if(fpIn == NULL)
    CString errMsg;
    errMsg.Format( "Could not open %d file : %s",
                   i + 1,
    delete buff;

  // Retieve file size file 
  UINT nFSize = ftell(fpIn);

  // Extract just file name from full pathname of file
  for(int nCtr = 0,nMid = 0;nCtr < inFName.GetLength();++nCtr)
    if(inFName[nCtr] == '\\' || inFName[nCtr] == ':')
      nMid = nCtr + 1;
  CString onlyFName = inFName.Mid(nMid);

  // Realloc previous buffer to accomodate this file's info
  LPSTR newbuff = new char[nSize +
                           (onlyFName.GetLength() + 1) +
                           sizeof(UINT) + nFSize];
  delete buff;
  buff = newbuff;

  // Copy file name with null character
  memcpy( buff + nSize,
          onlyFName.GetLength() + 1);
  // Copy file size
  *(UINT *)(buff + nSize + onlyFName.GetLength() + 1) = 
  // Copy file data
  VERIFY(fread( buff + nSize + 
                sizeof(UINT) + 
                (onlyFName.GetLength() + 1),
         1,nFSize,fpIn) == nFSize);

  nSize += sizeof(UINT) + 
           (onlyFName.GetLength() + 1) +

// Create a dummy EXE from ExeExtractor
FILE* fpOut = fopen(m_outFName,"wb");
if(fpOut == NULL)
  AfxMessageBox("Could not create output file" +
  delete buff;

// Find Load and Lock resource
HRSRC hResLoad = FindResource(NULL,
HGLOBAL hResData = LoadResource(NULL,hResLoad);
LPCSTR data = (LPCSTR)LockResource(hResData);

// Write the ExeCreator binary data to this file
ASSERT(hResLoad != NULL && hResData != NULL && data != NULL);

// Open the file for addition of file data in resource
HANDLE hUpdateRes = BeginUpdateResource(m_outFName, FALSE);
ASSERT(hUpdateRes != NULL);

// Add the file data to the update list.
delete buff;

// Write changes and then close it. 
VERIFY(EndUpdateResource(hUpdateRes, FALSE));


Download demo project - 24 Kb
Download source - 7 Kb


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date