Reputation: 393
I was wondering that how can i open any application in windows by using c++ programming, i am using dev c++. I used system()
but it is not performing well or i am not using it correctly. Kindly tell me the syntax of system()
to open an application or tell another function.
Upvotes: 3
Views: 170
Reputation: 2814
Use shell execute instead of system for windows.
#include <Windows.h>
//Link with library: Shell32.lib or libshell32.a
ShellExecute(
NULL, //handle to the parent window
"open", //Action to take
"Notepad.exe", //Program path
"arg1 arg2", //Command line arguments
"C:\\", //Start in what directory
SW_SHOWMAXIMIZED //Window state
);
As for system(), it only takes one argument which is the same as you would type in the console (cmd.exe)
for example
system("dir /a");
does exactly the same as typing dir /a
in cmd.exe
If you have trouble in building in devC++ check the project properties.
From 'Project options'>Directories>
\MinGW64\x86_64-w64-mingw32\lib32
\MinGW64\x86_64-w64-mingw32\include
From 'Project options'>Parameters> Linker
-lshell32
Upvotes: 4
Reputation: 6436
Did you try CreateProcess ?
CreateProcess(lpApplicationName
NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
lpStartupInfo,
lpProcessInformation
)
Upvotes: 0