How do I start an external windows app from VC++? It is a third party app, and not one of the standard win apps like notepad, calculator etc.
Printable View
How do I start an external windows app from VC++? It is a third party app, and not one of the standard win apps like notepad, calculator etc.
If you have the file name, you can use either ShellExecute or CreateProcess (the first is easier, the second more powerful)
I'm using the following code, and get error: Parameter 7 cannot be converted from 'const int' to 'void *'
if (CreateProcess (
NULL, //1
"c:\\Program Files\\Explosive Experts\\RL26DatabaseOptimiser.exe",//*sPath,
NULL, //3
NULL, //4
FALSE,CREATE_NEW_PROCESS_GROUP, //5
NORMAL_PRIORITY_CLASS, //6
NULL,//7
NULL, //8
NULL))//9
Any idea what I can do?
OK I figured the error out, but now the code compiles, but the "RL26DataBaseOptimiser" is'nt started.
MSDN isn't helping, so could any member with more C++ experience than me (arguably 99% :( ) please give me ahand?
[code]
if (CreateProcess (
"RL26DatabaseOptimiser.exe",//NULL, //1
"c:\\Program Files\\Explosive Experts\\RL26DatabaseOptimiser.exe",//*sPath,
NULL, //3
NULL, //4
FALSE,//5
DETACHED_PROCESS,//CREATE_NEW_PROCESS_GROUP, //6
NULL,//NORMAL_PRIORITY_CLASS, // 7
NULL,//8
NULL, //9
NULL))//10
{
//close this app
OK, how do I use the structs? I'm new to C++ so IV tried the following without success
Code:
iResult = MessageBox(NULL,"Tester must be closed for Database optimising. Do you want shut Tester down now?",
"Close Tester?",MB_YESNO | MB_ICONQUESTION );
typedef struct _STARTUPINFO { // si
DWORD cb;
LPTSTR lpReserved;
LPTSTR lpDesktop;
LPTSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
} STARTUPINFO, *LPSTARTUPINFO;
//STARTUPINFO lpStartInfo;
switch (iResult)
{
case IDYES: // The Yes button?
if (CreateProcess (
"c:\\Program Files\\Explosive Experts\\RL26DatabaseOptimiser.exe",//"RL26DatabaseOptimiser.exe",//NULL, //1
NULL,//2
NULL, //3
NULL, //4
FALSE,//5
DETACHED_PROCESS,//CREATE_NEW_PROCESS_GROUP, //6
NULL,//NORMAL_PRIORITY_CLASS, // 7
"c:\\Program Files\\Explosive Experts",//NULL,//8
GetStartupInfo(LPSTARTUPINFO&),//NULL, //9
NULL))//10
Go to the tutorials (top of page) and read some basic C++ tutorial. You seem to need it.
You only need to define the struct once, and in case of STARTUPINFO it is already defined in windows.h (actually winnt.h or wincore.h or something like that). Once a struct us defined, you can create an object like this:
STARTUPINFO si;