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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

trinitrotolueneDirector - Software EngineeringCommented:
you can invoke as follows:

just replace the C: with the path to the executable you want to run

Open in new window

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
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 ?
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

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;
	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,
	while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
			   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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
>> Not exactly i was looking for

Then you don't have to close the question, and can just ask for clarification where needed.
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.