?
Solved

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

Posted on 2008-11-13
7
Medium Priority
?
356 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:LearningCpp
7 Comments
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 22957348
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
 

Author Comment

by:LearningCpp
ID: 22957702
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 22958023
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
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.

 
LVL 86

Accepted Solution

by:
jkr earned 1500 total points
ID: 22961301
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
 

Author Comment

by:LearningCpp
ID: 23036910
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 23040862
>> Not exactly i was looking for

Then you don't have to close the question, and can just ask for clarification where needed.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 23040869
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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 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.
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.

850 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