Developing applications under MS-Windows

This page is mainly written for UNIX developers who want to become familiar with MS development.

First read or skim through the [http://msdn2.microsoft.com/en-us/library/xw1ew2f8(VS.80).aspx Introduction to Visual C++ for UNIX Users] on the [http://msdn2.microsoft.com/en-us/default.aspx Microsoft Developer Network].

(MSDN is Microsoft’s website for software developers. It provides resources that explain how to build software solutions and applications on the Microsoft platform.)

Compiling and running "Hello World" on the command line

Use any editor of your choice to create the following program in a test folder:

#include <stdio.h>

int main()
{
        printf("Hello world!\n");
}

Open a DOS box ("Command Prompt"), cd to your test directory, and perform the following steps:

D:\test>dir
 Volume in drive D is WIN_DAT
 Volume Serial Number is F00B-2B98

 Directory of D:\test

01/23/2008  01:31 PM    <DIR>          .
01/23/2008  01:31 PM    <DIR>          ..
01/23/2008  01:31 PM                68 helloworld.c
               1 File(s)             68 bytes
               2 Dir(s)  14,618,644,480 bytes free

D:\test>"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
Setting environment for using Microsoft Visual Studio 2005 x86 tools.

D:\test>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

D:\test>cl helloworld.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

helloworld.c
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:helloworld.exe
helloworld.obj

D:\test>dir
 Volume in drive D is WIN_DAT
 Volume Serial Number is F00B-2B98

 Directory of D:\test

01/23/2008  01:39 PM    <DIR>          .
01/23/2008  01:39 PM    <DIR>          ..
01/23/2008  01:31 PM                68 helloworld.c
01/23/2008  01:39 PM            53,248 helloworld.exe
01/23/2008  01:39 PM               612 helloworld.obj
               3 File(s)         53,928 bytes
               2 Dir(s)  14,618,583,040 bytes free

D:\test>helloworld
Hello world!

Note: If you open a command prompt with the Visual Studio Command Line Prompt from the Start menu, then vsvars32.bat is run for you.

Using the Development Environment

It is easier to use the development environment to edit and build your source code in a project. A project is a collection of source and related files that will be compiled into a single unit, such as a library or executable. A project also contains information on how the files are to be built. Information about projects is stored in a project file with the extension .prj.

An application that consists of multiple libraries and executables, each potentially built with a different set of compiler options or even in a different language, are stored in multiple projects that are part of a single solution. A solution is an abstraction for a container to group multiple projects together. Information about solutions is stored in a solution file with the extension .sln.

You can create new projects in the development environment. Visual C++ provides numerous templates that provide standard code for various common projects. You can use application wizards to generate projects with code outlines for various application types.

You can start with an empty project by using the Console Application (Win32) Wizard. Select the Empty Project check box. You can then add new and existing files to the project later.

To start with an empty project without a wizard, do the following:

How to enable debugging

(For a discussion why debugging is not enabled by default see [http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=811132&SiteID=1 here].)

  1. Goto Project->TestProject Properties

  2. On the left expand "Configuration Properties"
  3. Expand "C/C++"
  4. On the left, Select "General"
  5. On the right, change "Debug Information Format" to "Program Database For Edit And Continue (/ZI)"
  6. On the left, Select "Optimization"
  7. On the right, change "Optimization" to "Disabled (/Od)"
  8. On the left, expand "Linker"
  9. On the left, select "Debugging"
  10. On the right, change "Generate Debug Info" to "Yes"
  11. Click ok
  12. Set your breakpoints: Point to a line, right mouse click, Breakpoint -> Set Breakpoint

  13. Build -> Rebuild TestProject

  14. Debug -> Start Debugging

From now on, the usual work cycle is

  1. Add more files and/or edit your code
  2. Press F7 (Build Solution)
  3. Press F5 (Start Debugging)