Solved

EXE File Self-Extract

Posted on 2000-03-15
6
441 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

626 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