Sireiz
Sireiz

Reputation: 393

Opening a windows application like a game or a browser or any other program with c++

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

Answers (2)

Lefteris E
Lefteris E

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>

  • Library Directories \MinGW64\x86_64-w64-mingw32\lib32
  • Include Directories: \MinGW64\x86_64-w64-mingw32\include

From 'Project options'>Parameters> Linker

  • -lshell32

Upvotes: 4

sqlab
sqlab

Reputation: 6436

Did you try CreateProcess ?

CreateProcess(lpApplicationName
               NULL, NULL, NULL,
               NULL, NULL, NULL, NULL,
               lpStartupInfo,
               lpProcessInformation
              )

Upvotes: 0

Related Questions