Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

EXE File Self-Extract

Posted on 2000-03-15
6
434 Views
Last Modified: 2010-04-10
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
Comment
Question by:masvmasv
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2621276
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
 
LVL 22

Expert Comment

by:nietod
ID: 2621290
That link only has the 16 bit version.  try

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

instead.
0
 
LVL 32

Accepted Solution

by:
jhance earned 350 total points
ID: 2621551
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:masvmasv
ID: 2625035
Thanks

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

Excuse me for my bad english

Thanks...
0
 
LVL 32

Expert Comment

by:jhance
ID: 2625456
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
 

Author Comment

by:masvmasv
ID: 2625964
Thanks...
I dont test it...
But I send the points to you...


thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question