ExeCreator Utility | CodeGuru

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. ExeCreator: It is the main application which provides GUI for receiving file names to be added, […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 21, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

ExeCreator:
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.

ExeExtractor:
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;
  m_InList.GetText(i,inFName);
  // Open i file 
  FILE* fpIn = fopen(inFName,”rb”);
  if(fpIn == NULL)
  {
    CString errMsg;
    errMsg.Format( “Could not open %d file : %s”,
                   i + 1,
                   (LPCSTR)inFName);
    AfxMessageBox(errMsg);
    delete buff;
    return;
  }
  // Retieve file size file 
  fseek(fpIn,0,SEEK_END);
  UINT nFSize = ftell(fpIn);
  fseek(fpIn,0,SEEK_SET);
  // 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];
  memcpy(newbuff,buff,nSize);
  delete buff;
  buff = newbuff;
  // Copy file name with null character
  memcpy( buff + nSize,
          (LPCSTR)onlyFName,
          onlyFName.GetLength() + 1);
  // Copy file size
  *(UINT *)(buff + nSize + onlyFName.GetLength() + 1) =
                                                    nFSize;
  // Copy file data
  VERIFY(fread( buff + nSize +
                sizeof(UINT) +
                (onlyFName.GetLength() + 1),
         1,nFSize,fpIn) == nFSize);
  nSize += sizeof(UINT) +
           (onlyFName.GetLength() + 1) +
           nFSize;
  fclose(fpIn);
}
// Create a dummy EXE from ExeExtractor
FILE* fpOut = fopen(m_outFName,”wb”);
if(fpOut == NULL)
{
  AfxMessageBox(“Could not create output file” +
                m_outFName);
  delete buff;
  return;
}
// Find Load and Lock resource
HRSRC hResLoad = FindResource(NULL,
           MAKEINTRESOURCE(IDR_IDR_EXE_EXEEXTRACTOR),
           “IDR_EXE”);
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);
fwrite(data,1,SizeofResource(NULL,hResLoad),fpOut);
fclose(fpOut);
FreeResource(hResData);
// 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.
VERIFY(UpdateResource(hUpdateRes,
    “IDR_EXE”,MAKEINTRESOURCE(IDR_IDR_EXE_EXEEXTRACTOR),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
    buff,nSize));
delete buff;
// Write changes and then close it. 
VERIFY(EndUpdateResource(hUpdateRes, FALSE));

Downloads

Download demo project – 24 Kb

Download source – 7 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.