10 Replies - 10843 Views - Last Post: 09 November 2009 - 12:28 AM Rate Topic: -----

#1 shockin!   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 136
  • Joined: 19-October 09

Open External Program C++

Post icon  Posted 07 November 2009 - 09:22 PM

Okay so I'm JUST starting c++, and was wondering, how can I open an external program (for example notepad.exe) in c++?
Is This A Good Question/Topic? 0
  • +

Replies To: Open External Program C++

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Open External Program C++

Posted 07 November 2009 - 09:24 PM

Can you further describe open?

Do you mean open to edit the source code, or open as in launch?
Was This Post Helpful? 0
  • +
  • -

#3 shockin!   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 136
  • Joined: 19-October 09

Re: Open External Program C++

Posted 07 November 2009 - 09:34 PM

When I say open I mean to launch the program.e
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Open External Program C++

Posted 07 November 2009 - 09:38 PM

issue System with the full path to the program. Since notepad.exe is in the Windows path, you are free to exclude the full path.
Was This Post Helpful? 0
  • +
  • -

#5 shockin!   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 136
  • Joined: 19-October 09

Re: Open External Program C++

Posted 07 November 2009 - 09:53 PM

Wait, what?
I'm confused.
Was This Post Helpful? 0
  • +
  • -

#6 gronk   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 168
  • Joined: 28-October 09

Re: Open External Program C++

Posted 08 November 2009 - 04:12 AM

View Postshockin!, on 7 Nov, 2009 - 08:53 PM, said:

Wait, what?
I'm confused.


Yep, that's to be expected. Ask a little later in your understanding of C++; get the basics sorted out before you try more complicated things.

But I see no harm showing you the code. Build a console application using Visual Studio* and give it the following:
#include <stdlib.h>
int main()
{
	system("notepad.exe");
	return 0;
}


Build and run it, and Notepad will appear as directed.

*In VS2008: File -> New Project. In Project Types select Visual C++ -> Win32, and in Templates select Win32 Console Application. Give the project a name, check the location is fine, ensure "Create new solution" is selected, doesn't matter if Create Directory is selected or not (I prefer not) and click OK. In the App Wizard click Next, the defaults should be fine so click Finish and it'll drop you into a code editor. Replace
int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}


with the above, select Build->Build Solution to build it; there shouldn't be any errors if you've followed the above instructions *exactly*, then Ctrl-F5 to run it.
Was This Post Helpful? 0
  • +
  • -

#7 Crunch   User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: Open External Program C++

Posted 08 November 2009 - 04:19 AM

try this also
#include <windows.h>

int main(){

ShellExecute(GetDesktopWindow(), "open", "notepad", NULL, NULL, SW_SHOWNORMAL);  
	
return 0;
	
}


Was This Post Helpful? 0
  • +
  • -

#8 shockin!   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 136
  • Joined: 19-October 09

Re: Open External Program C++

Posted 08 November 2009 - 01:20 PM

The system code doesn't work for reason: system identifier not found.
Was This Post Helpful? 0
  • +
  • -

#9 gronk   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 168
  • Joined: 28-October 09

Re: Open External Program C++

Posted 08 November 2009 - 03:00 PM

What compiler are you using?
Was This Post Helpful? 0
  • +
  • -

#10 shockin!   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 136
  • Joined: 19-October 09

Re: Open External Program C++

Posted 09 November 2009 - 12:04 AM

Visual Studio 2010 Beta2, that's all I know.
Was This Post Helpful? 0
  • +
  • -

#11 hackterr   User is offline

  • D.I.C Regular

Reputation: 21
  • View blog
  • Posts: 293
  • Joined: 13-August 09

Re: Open External Program C++

Posted 09 November 2009 - 12:28 AM

you must include header files for using system or shellexecute
and the program must run from a location where notepad.exe is available
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1