|MadSci Network: Computer Science|
This isnít a simple question. Iíll start with some background so you can see the real problem, then follow with some concrete suggestions. C++, like most languages, is rather myopic. The language doesnít know there is a real world out there. It has no idea what operating system it is running under, whether there are any other programs, or what I/O devices are available. The libraries that come with the language make some assumptions. They assume, for example, that there is some way to send text somewhere and some way to get text from the outside world. In point of fact, though, some useful C++ programs run in an environment where these assumptions are not valid. Youíre probably starting to see why you canít find information about how to run an application in C++ books. The simple answer is that C++ canít do it, at least not directly. C++ relies on libraries that may or may not exist in a particular environment to get the job done. The only facility that Iím aware of that comes close to being available in all implementations of C++ is the system() function. This function takes a string and passes it to a command processor. There are a lot of potential problems with system(), though. There is no guarantee that a command processor exists in a particular implementation of C++. Even if there is something on the other end listening to the commands you send, it may not be capable of launching an application. I didnít have any luck using system() to launch an application on Windows 95 using Microsoft VC++, for example. You can find the system() function documented in any decent book on C or C++ . My favorite is C, A Reference Manual, Harbison & Steele, Tartan Laboratories. It's a C book, not C++, but it does describe system(). What youíll probably end up using is a library that is specific to the operating system youíre using instead of something that is in every implementation of C++. As an example, you will probably use ShellExecute if your application runs on Windows. You might pick WinExec or CreateProcess instead, though. If youíre running on some other operating system, youíll use some other OS level call, but itís impossible to name it without knowing the specific OS you are using. Assuming for a moment that youíre running under some flavor of Windows, though, start by looking for ShellExecute in your online documentation. If thatís unavailable, or you arenít finding what you need, try www.microsoft.com. A search for ShellExecute will turn up dozens of listings, from documentation of the command itself to several programming examples in a variety of languages. Mike Westerfield Byte Works, Inc.
Try the links in the MadSci Library for more information on Computer Science.