Search code examples
c++visual-c++visual-c++-2010crt

Minimalistic Visual C++ app which shows a window


I'm trying to create a C++ application in Visual Studio 2010 which matches the following criteria:

  1. Displays an empty window
  2. Is small as possible (say, under 100kb)
  3. Runs on fresh empty install of Windows XP (does not require any runtimes, libraries, etc)

Basically, I want to get rid of runtime. The only thing I need is to call WinAPI functions to display a window and BitBlt something to it's surface.

Is it possible?


Solution

  • 1/2: Visual Studio can generate a bare-bones template, which is exactly what you need (displays an empty window). Use File -> New -> New Project -> select 'Win32 Project' -> click 'Finish' to create the project. The Release\Win32 binary is 81KB when statically linking to the C run-time library (more on this below). Of course, adding your code will likely increase the binary size. You may want to look at optimization settings or even binary compression to minimize size. The latter I would not recommend due to frequent false positives from anti-virus software.

    3: You will need to statically link to the C run-time library. This can be configured under Configuration Properties -> C/C++ -> Code Generation -> Runtime Library (select /MT for release and /MTd for debug). Doing so will allow you to run the executable without the presence of the Visual C++ 2010 redistributable package installation.

    Note that binaries compiled with Visual Studio 2010 require Windows XP SP2 or higher. You may wish to check this workaround if you need to target pre-SP2 versions of Windows XP.