This is geared towards MSVC 2008 but it should be compatible.
[1] create an empty Win32 Console Application.
[2] Then set the Configuration to "Release"
[3] Now add a new cpp file to the project (Project -> Add New Item) named tiny.cpp
[4] Paste the following into tiny.cpp
#include <windows.h>
int main(void)
{
MessageBoxA(0, "Hello World!", 0, 0);
return 0;
}
[5] Build the solution (Build -> Build Solution) and you should get a 7KB executable.
[6] Open the Project Settings DialogBox (Project -> Properties) and apply the
following settings:
Configuration Properties - General - Character Set - Not Set
Configuration Properties - Manifest Tool - Input and Output - Embed Manifest - No
Configuration Properties - Build Events - Post Build Events - Command Line - cmd /c dir "$(TargetPath)"
Configuration Properties - C/C++ - General - Debug Information Format - Disabled
Configuration Properties - C/C++ - Optimization - Omit Frame Pointers - Yes
Configuration Properties - C/C++ - Optimization - Enable Fibre Safe Optimizations - Yes
Configuration Properties - C/C++ - Code Generation - Enable C++ Exceptions - No
Configuration Properties - C/C++ - Code Generation - Runtime Library - Multi Threaded DLL
Configuration Properties - C/C++ - Code Generation - Buffer Security Check - No
Configuration Properties - Linker - Input - Ignore Default Libraries - Yes
Configuration Properties - Linker - Manifest File - Generate Manifest - No
Configuration Properties - Linker - Debugging - Generate Debug Info - No
Configuration Properties - Linker - Advanced - Randomize Base Address - Default
Configuration Properties - Linker - Advanced - Data Execution Prevention - Default
[7] Replace the contents of tiny.cpp with the following:
#include <windows.h>
void mainCRTStartup(void)
{
MessageBoxA(0, "Hello World!", 0, 0);
return;
}
[8] Rebuild the solution (Build -> Rebuild Solution) and you should get a 2KB program.
[9] Back in the Project Settings DialogBox (Project -> Properties) add the following
command line arguments to the linker:
Configuration Properties - Linker - Command Line - Additional Options -
/ALIGN:16
/filealign:16
/ignore:4108
[10] Rebuild the solution (Build -> Rebuild Solution) and you should get it down to 672 bytes.
[11] Return to the Project Settings (Project -> Properties) replace the previous
Command Line Arguments for the linker with this new and revised version:
Configuration Properties - Linker - Command Line - Additional Options -
/MERGE:.rdata=.data
/MERGE:.data=.text
/ignore:4254
/SECTION:.text,RWE
/ALIGN:16
/filealign:16
/ignore:4108
[12] After rebuilding (Build -> Rebuild Solution) you should be greeted with an executable thats only 608 bytes.
[13] Create a new file called stub.asm and paste the following into it:
format binary as 'exe'
mzhdr: ;
.e_magic dw "MZ" ;
.e_cblp dw 0x0090 ;
.e_cp dw 0x0003 ;
.e_crlc dw 0x0000 ;
.e_cparhdr dw 0x0004 ;
.e_minalloc dw 0x0000 ;
.e_maxalloc dw 0xFFFF ;
.e_ss dw 0x0000 ;
.e_sp dw 0x00B8 ;
.e_csum dw 0x00C3 ; .entry: ret
.e_ip dw 0x0012 ; @.entry
.e_cs dw 0x0000 ;
.e_lsarlc dw 0x0040 ;
.e_ovno dw 0x0000 ;
.e_res dw 4 dup ? ;
.e_oemid dw 0x0000 ;
.e_oeminfo dw 0x0000 ;
.e_res2 dw 10 dup ? ;
.e_lfanew dd 0x00000000 ;
[14] Assemble stub.asm using FASM and you should see a file stub.exe thats 64 bytes.
[15] Back in Visual Studio's Project Settings (Project -> Properties) we're going to
over-ride the default stub with our own custom stub. Replace the existing linker
Command Line Arguments with the following:
Configuration Properties - Linker - Command Line - Additional Options -
/STUB:$(SolutionDir)stub.exe
/MERGE:.rdata=.data
/MERGE:.data=.text
/ignore:4254
/SECTION:.text,RWE
/ALIGN:16
/filealign:16
/ignore:4108
[16] Rebuild the Solution (Build -> Rebuild Solution) and you have 560 bytes.
[17] Then take the patched version of link.exe that I supply here and place it in your project directory and rebuild
480 bytes
any lower than that and you'll have to use an assembler.
But this is a lot of work for little reward. Best to just use a good compressor such as crinkler.
Edit : Va!n here's the same project you posted but got the size down to 944 bytes using the above settings.