Friday, December 16, 2011

Create HelloWorld of Win32 Console Application using Microsoft Visual C++ 2010 Express

- Start Microsoft Visual C++ 2010 Express, click New Project...

New Project...in Microsoft Visual C++ 2010 Express

- Select Win32 under Visual C++ in Installed Templates from the left, and select Win32 Console Application from the middle, Enter Name (HelloWin32Console) and click OK.
Setup project

- Win32 Application Wizard will list current project settings, click Finish.
Project setting

- A dummy project of Win32 console application will be generated. Notice that a function of _tmain(int argc, _TCHAR* argv[]) is generated, it have the same function as main() in normal C++ program.
Dummy code generated by Application Wizard

- Modify HelloWin32Console.cpp as listed below:
// HelloWin32Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
 std::cout << "Hello Win32 Console Application!" << std::endl;
 std::cout << "Press ENTER key to exit." << std::endl;
 getchar();

 return 0;
}

Modify the code

- Click File -> Save All (or Ctrl+Shift+S) to save all the works.
- Click Debug -> Build Solution (or F7) to build the application.
- Click Debug -> Start Debugging (or F5) to run it.
HelloWin32Console run in console

No comments:

Post a Comment