Solved

EXE File Self-Extract

Posted on 2000-03-15
6
438 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
[X]
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
  • 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
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!

 

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

Technology Partners: 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!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 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