Datasheet
720
Creating a New Win32 Console Application
In most respects, this code doesn’t look much different from code you type
in CodeBlocks. The example begins by including stdafx.h, which contains
the list of common declarations for the example as described earlier. As with
any C++ application, you must also include a namespace declaration.
The body of the example application looks similar to other examples in this
book. The basic idea is to output some text to the command prompt and
then pause until the user presses Enter.
The big difference is the use of _tmain() rather than main(). The _
tmain() function declaration appears in tchar.h. If you look at this file,
you’ll see that using _tmain() expands to either main() (when working
with ANSI characters) or wmain() (when working with Unicode characters).
In short, _tmain() is simply a convenience that lets you compile your code
for either ANSI or Unicode use as needed without having to change your
application code. Microsoft provides a number of _t* declarations in the
tchar.h file, and you may want to look at them at some point.
Running the application
At this point, your application is ready to compile and run. To compile an
application using Visual C++, you choose Build➪Build Solution. In the Output
window, you see a series of build messages like the ones shown in Figure 1-3.
If there are any errors when you compile your application, you see them in
the Error List window (simply click the Error List tab shown in Figure 1-3 to
see the errors).
Figure 1-3:
The Output
window
shows
the steps
used to
compile the
application.
To see your application in action, click Start Debugging (the green arrow) on
the Standard toolbar or press F5. If you want to start your application with-
out debugging support, choose Debug➪Start Without Debugging or press
Ctrl+F5. Figure 1-4 shows the output from this application.
44_317358-bk07ch01.indd 72044_317358-bk07ch01.indd 720 7/22/09 11:44:51 PM7/22/09 11:44:51 PM