The MP3car.com Store  

Welcome to the MP3Car.com forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Registering will also remove advertisements. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   MP3Car.com > Mp3Car Technical > Software & Software Development

Reply
 
Thread Tools Display Modes
Old 10-09-2002, 09:39 PM   #1
Constant Bitrate
 
Join Date: Jul 2001
Location: Richmond, VA USA
Vehicle: 1985 4x4 S-10 Blazer
Posts: 217
My Photos: (0)
Running a program inside a program

I have no idea what this would be called, but im sure there is a technical term like nested execution or something. Anyway I am using Visual C++ and learning all I can... I know the general structure and functions and all so if you give me code, I will more than likely understand it. All I want to know is how to call a program like I would on a command line (like the run command).

So if I went to run and typed in
"C:\Program FIles\Winamp\winamp.exe"

Winamp would run. How can I do this in Vis C++??? (not neccesarily just like that, but how can a program be called to run from inside of a program?)

Edit: I want to know how to do this in general for any program, not just winamp

Thanks in advance for any help.

-Josh
__________________
Josh Karger
By reading this post you agree to overlook all grammatical, spelling, and typographical errors! ;)

Last edited by CaffeineAddict : 10-09-2002 at 10:06 PM.
CaffeineAddict is offline   Reply With Quote
Sponsored Links
Old 10-09-2002, 10:22 PM   #2
Registered User
 
Join Date: May 2002
Location: Gorge of eternal peril
Vehicle: 2003 BMW M3
Posts: 134
My Photos: (0)
What type of project are you building? You have two options:

Code:
WinExec("C:\\Program Files\\Winamp\\winampa.exe", SW_SHOWMINIMIZED);

This executes something as if you had just dbl clicked its icon.

or

Code:
system("C:\\Program Files\\Winamp\\winampa.exe");

This will pop up a command prompt window and executes what you typed as if you had typed it. Youll see what I mean when you try it.

Also make sure you use "\\" to represent one \. Thats similiar to typing "\n" or "\t" etc...

Hope that helps
__________________
'03 BMW M3 6 spd.
Black/Imola Red
19's

Shuttle XPC w/ AMD 1800+
Opus 150w
Lilliput 7"
Wireless internet through my P900 and bluetooth

Last edited by InFix : 10-09-2002 at 10:25 PM.
InFix is offline   Reply With Quote
Old 10-09-2002, 10:24 PM   #3
Constant Bitrate
 
samael's Avatar
 
Join Date: May 2001
Location: new zealand
Posts: 130
My Photos: (0)
fork

fork the code using the command fork. This will create another process (i have only done this in linux , i think in windows it creates a thread which is kind of the same). The use exec.
pseudocode :

doSomeStuff();
fork();

if (i am not parent process) {
exec(c:\programfiles\winamp);
}

if you exec something , the process is terminated. so this :

doSomeStuff();
exec(aprogram);
printf("hello"):

hello will never appear as when you exec , the exec-ing processs is terminated. If you dont care about what happens to the program after you exec then dont bugger around with fork
and BTW take this with a grain of salt , this is from memory and may be slightly wrong
__________________
stupid quote # 1 : "i dont do drugs , i only ever smoke pot when i'm coming down" , Me , 6 september , 2001.
samael is offline   Reply With Quote
Old 10-09-2002, 10:46 PM   #4
Constant Bitrate
 
Join Date: Jul 2001
Location: Richmond, VA USA
Vehicle: 1985 4x4 S-10 Blazer
Posts: 217
My Photos: (0)
InFix, This looks like it will work (the first option (such as dbl click) is what I was going for). Once again you have helped me tremendously.

samael it really doesn't matter in this case because the program will always be running in the background.

I used winamp as an example... but what I am actually doing is making a call to my home automation program. I always turn my house into a haunted house for halloween, and I want to be able to activate some madules and then turn them off seconds later... unfortunately the software (ActiveHome) only allows incrementing in minutes so I could have something come on and I couldn't have it automatically go off for at least 1 min. With this program and system there are housecodes A-P and module numbers 1-16. So K10 could be a lamp and K5 could be the coffee maker. With ActiveHome you can address the path like this:

D:\Program Files\Home Control\X10COMM.EXE k10 on

and that would turn my lamp on. So using the code InFix provided doing this would turn the lamp on from my program:

WinExec("D:\\Program Files\\Home Control\\X10COMM.EXE k10 on", SW_SHOWMINIMIZED);

now I can just do some filling in to make it wait and then do the same except it says "k10 off " and that will turn my lamp off.

I know my methods aren't exactly the best coding, but im only going to whip this together to use for halloween, so as long as it works for me... im happy.

Of course I just got another cool idea while writing this. Turn a light on and open winamp to play a sound such a a scream. Then close winamp, turn light off, and wait a predetermined time later then repeat. So I guess Samael I will have to check to see what is running and all that. For those interested,and want more info on X10 check out:

www.x10.com -I dont really reccommend this site too much, but they have some products... a better is:
www.smarthome.com
comp.home.automation

Also if anyone is interested, let me know and I'll post the code showing the full effect.

I think a high tech edge is going to get some trick-or-treaters this year!!!

-Josh
__________________
Josh Karger
By reading this post you agree to overlook all grammatical, spelling, and typographical errors! ;)
CaffeineAddict is offline   Reply With Quote
Old 10-09-2002, 10:55 PM   #5
Registered User
 
Join Date: May 2002
Location: Gorge of eternal peril
Vehicle: 2003 BMW M3
Posts: 134
My Photos: (0)
Glad to help. If you want winamp to play a file, you have to do this:

Code:
WinExec("C:\\Program Files\\Winamp\\winampa.exe \"d:\\music\\file.mp3\"", SW_SHOWMINIMIZED);

Notice the \", thats the escape sequence for the ". So if you were to run winamp on the command line you would type:

winamp "myfile.mp3"

So to get that effect you do the \"myfile.mp3\" as the paramater

Also, I would recommend NOT hardcoding that in, so you could do this:

Code:
CString path; path.Format("%s \"%s\"", "C:\\Program Files\\Winamp\\winamp.exe ", someFunction()); WinExec(path, SW_SHOWMINIMIZED);

where someFunction() will return either a char* or CString with the file name that you want in it.

Anyway, let me know how that turns out, sounds very intresting! :P
__________________
'03 BMW M3 6 spd.
Black/Imola Red
19's

Shuttle XPC w/ AMD 1800+
Opus 150w
Lilliput 7"
Wireless internet through my P900 and bluetooth
InFix is offline   Reply With Quote
Old 10-09-2002, 11:25 PM   #6
Constant Bitrate
 
Join Date: Jul 2001
Location: Richmond, VA USA
Vehicle: 1985 4x4 S-10 Blazer
Posts: 217
My Photos: (0)
You are a mind reader... and you're scaring me. I just tried to get it to play a file and then open a playlist and couldn't get it figured out, searching google didn't help and I was about to ask when I refreshed the post to see if there were any replies... and boom there you are. Anyway one question, I have been trying to decipher the windows.h file but no luck there... is there any sites that lists all of the little pieces of syntax (for example one search did reveal a "SW_SHOWNORMAL") Which I see loads it just like well it hurts to point out, normal. I'm sure more searching on my part will yield something.

I fully understand your point about leaving it flexible to load any file through a string (ie not hardcoding) but I don't understand why you put:
Code:
path.Format("%s \"%s\"", "C:\\Program Files\\Winamp\\winamp.exe ", someFunction());

What is the point of the "%s \"%s\"" ?

-Josh

BTW I tried the code and didn't comprehend what you said about the escape sequence (/") then I re-read it and thought it over and remembered seeing something like that before and found my error and needless to say it works! Thanks again!
__________________
Josh Karger
By reading this post you agree to overlook all grammatical, spelling, and typographical errors! ;)
CaffeineAddict is offline   Reply With Quote
Old 10-09-2002, 11:32 PM   #7
Low Bitrate
 
Join Date: Sep 2002
Location: aychamo land
Posts: 92
My Photos: (0)
rofl

a lot of this was covered in my "Tips For Developers" thread that got turned into a "you are a sucky programmer" thread, then a big fight about somethign MFC or some junk I have no idea bout.

god bless that communist
__________________
AYCHAMO! http://www.aychamo.com
Bobby_Aychamo is offline   Reply With Quote
Old 10-09-2002, 11:37 PM   #8
Registered User
 
Join Date: May 2002
Location: Gorge of eternal peril
Vehicle: 2003 BMW M3
Posts: 134
My Photos: (0)
As far as all the little syntax things go, there's a ton of sites out there, but my main source is the 2 msdn discs that come with vc++. It has everything you could possibly every want, as far as windows programming goes. Online though, for MFC, try www.codeguru.com great site, and has tons of info. Also, www.codeproject.com

As for the %s stuff, that is identical to the oldschool C printf function. Like printf("%s", string); where string is a char*, will print whatever is in string. printf("%d", aNumber); where aNumber is an int, will print the number. Its a little hard to explain, but just lookup printf + format in google and I guarentee there will be a million pages explaining it
__________________
'03 BMW M3 6 spd.
Black/Imola Red
19's

Shuttle XPC w/ AMD 1800+
Opus 150w
Lilliput 7"
Wireless internet through my P900 and bluetooth

Last edited by InFix : 10-09-2002 at 11:41 PM.
InFix is offline   Reply With Quote
Old 10-09-2002, 11:58 PM   #9
Constant Bitrate
 
Join Date: Jul 2001
Location: Richmond, VA USA
Vehicle: 1985 4x4 S-10 Blazer
Posts: 217
My Photos: (0)
Thanks fo rthe help tonight, the only thing about the tips for dev thread (which I was looking at and trying to relate) was that it didn't touch too much on the exact of c++ and was more vis basic I beleive. Either way call it sucky programming if you want (and I know you aren't and that charles was) but considering im whipping it up for one night (halloween) and it won't be any mroe than 15-20 lines MAX, I really don't care!

All I want is a little something that will run my show so I don't have to push the buttons...lol I might expand it later to use in the future

-Josh
__________________
Josh Karger
By reading this post you agree to overlook all grammatical, spelling, and typographical errors! ;)
CaffeineAddict is offline   Reply With Quote
Old 10-16-2002, 03:19 AM   #10
Constant Bitrate
 
Join Date: Sep 2002
Location: Redmond, WA
Vehicle: 2000 Lexus GS400
Posts: 171
My Photos: (0)
ShellExecute is the best way to execute a program and get information about the resulting process. (i.e. you can wait for it to spin up using WaitForInputIdle). With the handle you can use WaitForSingleObject to detect when the process has exited.

You could also use CreateProcess (which ShellExecute, WinExec, etc probably all map down to behind the scenes) , but it requires a zillion parameters that you probably don't care about (like security context, etc)
digitallexus is offline   Reply With Quote
Sponsored Links
Old 10-16-2002, 03:26 AM   #11
Constant Bitrate
 
Join Date: Sep 2002
Location: Redmond, WA
Vehicle: 2000 Lexus GS400
Posts: 171
My Photos: (0)
Code:
bool LaunchApplication (WCHAR *wszPath, WCHAR *wszExe, WCHAR *wszCommandLine) { SHELLEXECUTEINFO ExeInfo; ZeroMemory (&ExeInfo, sizeof (ExeInfo)); ExeInfo.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS; ExeInfo.cbSize = sizeof (SHELLEXECUTEINFO); ExeInfo.lpDirectory = wszPath; ExeInfo.lpParameters = wszCommandLine; ExeInfo.lpFile = wszExe; ExeInfo.nShow = SW_SHOWNORMAL; if (!ShellExecuteEx (&ExeInfo)) { // problem launching return false; } // wait for the app to start WaitForInputIdle( ExeInfo.hProcess, 30000); CloseHandle( ExeInfo.hProcess ); return true; }

This assumes you are compiling using UNICODE. Otherwise, change all WCHARs to char
digitallexus is offline   Reply With Quote
Sponsored Links
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT -5. The time now is 08:03 PM.


Sponsored Links
The MP3car.com Store

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0
Copyright © 1999 - 2008 Mp3Car.com Inc.
Ad Management by RedTyger
Message Board Statistics