ianmatchett
asked on
Launching Windows programs from a C++ program
Hi,
I asked a question a while ago that was answered, but I have found that I can only launch programs that can be launched from a MS-DOS prompt. My question is how do you launch Win programs from a C++ program? Like, for example, how would you launch Excel from your program.
Thanks.
Ian.
I asked a question a while ago that was answered, but I have found that I can only launch programs that can be launched from a MS-DOS prompt. My question is how do you launch Win programs from a C++ program? Like, for example, how would you launch Excel from your program.
Thanks.
Ian.
To open files in, for example, you can use ShellExecute; to launch processes you can use CreateProcess.
Sorry, I meant "in Excel, for example"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The following function "Execute" uses the CreateProcess function to call a program by a command line string. Therefor, you will have to quote the path to the executable if it contains whitespaces, as sampled in the main() routine I copied as well. The boolean return value indicates the success of CreateProcess, but I didn't check it here because ... well because it works ...
BOOL Execute(LPCSTR strPath)
{
PROCESS_INFORMATION pInfo;
STARTUPINFO sInfo;
GetStartupInfo(&sInfo);
return CreateProcess(NULL,(char*) strPath,
NULL,NULL,TRUE,NORMAL_PRIO RITY_CLASS ,
NULL,NULL,&sInfo,&pInfo);
}
int main (int argc, char **argv)
{
Execute("\"c:\\winnt\\syst em32\\ping .exe\" www.google.com"); // path to ping.exe quoted
return 0;
}
BOOL Execute(LPCSTR strPath)
{
PROCESS_INFORMATION pInfo;
STARTUPINFO sInfo;
GetStartupInfo(&sInfo);
return CreateProcess(NULL,(char*)
NULL,NULL,TRUE,NORMAL_PRIO
NULL,NULL,&sInfo,&pInfo);
}
int main (int argc, char **argv)
{
Execute("\"c:\\winnt\\syst
return 0;
}
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: mnashadka
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: mnashadka
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer