Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

EXE File Self-Extract

Hi...
I need a source code in Visual C++ or Borland C++ for make one EXE file with many files inside (self-extract).

thanks for all

If do you want, please, send the source code to me.. thanks

masvmasv@hotmail.com
0
masvmasv
Asked:
masvmasv
  • 2
  • 2
  • 2
1 Solution
 
nietodCommented:
There are commercial programs for doing this.  Its probably not worth writting this yourself.  Check out pklite at

http://www.pkware.com/pklite.html

i
0
 
nietodCommented:
That link only has the 16 bit version.  try

http://www.pkware.com/catalog/pklite.html

instead.
0
 
jhanceCommented:
I dug this out of my PAQ (previously asked questions) at:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=10220405 

Here is the essential code from that previous posting:

After giving this a little thought, I decided that I did have a pretty good idea on how to do it.  It seems you know how to create the DIFF file so I'll just show you how I created a small app that extracts the last part of itself into another file at run time.

First, the code:

#include "stdafx.h"
#include "PatchTest.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
const TCHAR *lpszDataMarker = _T("***BEGINNING-OF-DATA***");

// Get this executable file's name
LPBYTE pbBuffer;

TCHAR lpszExeName[_MAX_PATH+1];
::GetModuleFileName(NULL, lpszExeName, _MAX_PATH);

CFile mFile;
if(!mFile.Open(lpszExeName, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary)){
cerr << _T("Error opening EXE file: ") << lpszExeName << endl;
return 0;
}
cout << _T("EXE File opened OK") << endl;

// Allocate space for it
DWORD dwLength = mFile.GetLength();
pbBuffer = new BYTE[dwLength];

mFile.Read(pbBuffer, dwLength);

mFile.Close();

// Find the 1st occurrence of the lpszDataMarker
BOOL bFlag = FALSE;
LPBYTE p;
for(p=pbBuffer; p<(pbBuffer+dwLength)-_tcslen(lpszDataMarker); p++){
if(memcmp((LPVOID)lpszDataMarker, (LPVOID)p, _tcslen(lpszDataMarker)) == 0){
bFlag = TRUE;
break;
}
}

if(bFlag){
cout << _T("Found 1st at offset ") << (p - pbBuffer) << endl;
}
else{
cout << _T("Error marker not found...") << endl;
delete pbBuffer;
return 0;
}

// Now the 2nd one, the one we want
bFlag = FALSE;
for(p += _tcslen(lpszDataMarker);p<(pbBuffer+dwLength)-_tcslen(lpszDataMarker); p++){
if(memcmp((LPVOID)lpszDataMarker, (LPVOID)p, _tcslen(lpszDataMarker)) == 0){
bFlag = TRUE;
break;
}
}

if(bFlag){
cout << _T("Found 2nd at offset ") << (p - pbBuffer) << endl;

// Now extract everything after the marker to a file
p += _tcslen(lpszDataMarker);
CFile mFileNew;
mFileNew.Open(_T("EXTRACTED"), CFile::modeWrite | CFile::modeCreate);
mFileNew.Write(p, dwLength-(p-pbBuffer));
mFileNew.Close();
//
}
else{
cout << _T("Error 2nd marker not found.") << endl;
}

delete pbBuffer;
}

return nRetCode;
}


Then there is a text file with just a single line in it called MARKER.TXT.  It has in it:

***BEGINNING-OF-DATA***

Then use the DOS COPY command like this to append 3 files together into the EXE you are going to distribute:


C:\VCProjects\PatchTest\Debug>copy /B patchtest.exe /b + marker.txt /b + ..\Patchtest.cpp patch.exe /b

This appends the patchtest.exe, the marker.txt file, and the file to be extracted, in this case, the source code to the project and copies them into patch.exe

Now when you run patch.exe, you will get the contents of patchtest.cpp extracted into a file called EXTRACTED.

Enjoy....



0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
masvmasvAuthor Commented:
Thanks

One more question...
Your program need any DLL file or only a unique EXE File?

Excuse me for my bad english

Thanks...
0
 
jhanceCommented:
No DLLs (other than the standard Windows DLLs) are used in this program.  What I've posted here is complete.  It does use MFC (which I think is available on your Borland C++ but if not, it should be straightforward to remove all the MFC references.

I wanted to show you how this works in concept.  
0
 
masvmasvAuthor Commented:
Thanks...
I dont test it...
But I send the points to you...


thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now