I need to embed another exe in my own console application in C++

Hi experts,
I have created an application using c++, but now from my application i want to run another exe, but i want to embed this exe in my own project as a resource file.
Can i do it, if yes, can someone post a sample code, or logic as to how should i do it?
any pointers wil also be helpful

I am using VS2005

TIA
LearningCppAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
Take a look at http://www.codeproject.com/KB/winsdk/selfextract.aspx ("Pure WIN32 Self-Extract EXE Builder") - it demonstrates how to extract any resource to disk (and a lot more) and comes with full sample code.

After extracting it to disk, you can run the executable any way you want, e.g. like
DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd, BOOL bShow)
{
	STARTUPINFO         si;
	PROCESS_INFORMATION pi;
 
	BOOL                bRes;
 
	DWORD               dwCode  =   0;
 
	MSG				   msg;
 
	ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));
 
	si.cb           =   sizeof  (   STARTUPINFO);
	si.dwFlags      =   STARTF_USESHOWWINDOW;
	si.wShowWindow  =   bShow ? SW_SHOWNORMAL : SW_HIDE;
 
	bRes    =   CreateProcess   (   NULL,
								   pszCmd,
								   NULL,
								   NULL,
								   TRUE,
								   NORMAL_PRIORITY_CLASS,
								   NULL,
								   NULL,
								   &si,
								   &pi
							   );
 
	while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
																   &pi.hProcess,
																   FALSE,
																   INFINITE,
																   QS_ALLINPUT
															   )
		   )
		   {
			   while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
					   {
						   DispatchMessage     (   &msg);
					   }
		   }
 
	GetExitCodeProcess  (   pi.hProcess,    &dwCode);
 
	CloseHandle (   pi.hProcess);
	CloseHandle (   pi.hThread);
 
	return  (   dwCode);
}

Open in new window

0
 
trinitrotolueneDirector - Software EngineeringCommented:
you can invoke as follows:

just replace the C: with the path to the executable you want to run
system("C:\\yourexe.exe");

Open in new window

0
 
LearningCppAuthor Commented:
that is not what i am looking for.
Currently i have one exe on my machine ,say sleep.exe, from my VS2005 project i want to embed this exe in my project and create my own application mayapp.exe, and now i should have exe to run on another machine, which can do what myapp wants to do and also use sleep without having sleep on the other machine
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Infinity08Commented:
Can't you just copy the code for sleep.exe into your mayapp project ?

If you really need to embed the exe, then is it an option to just embed it as a resource, and when it'll be used, copy the resource into an actual file, and then call that executable ?
0
 
LearningCppAuthor Commented:
Not exactly i was looking for, but jkr always gives me some more technical explanation.
Its a great article, so points for the same
0
 
Infinity08Commented:
>> Not exactly i was looking for

Then you don't have to close the question, and can just ask for clarification where needed.
0
 
Infinity08Commented:
Note also that I asked you a few questions to which you never responded. Those responses were necessary to give you the best help possible.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.