Today I came up with a way to create a 1kB Hello World example using a dialog box. I don't think I have seen this before so I decided to post it here.

It's so small is because all sections are merged and I don't use an extra .rsrc section for the dialog-data. The dialog is stored as a byte array in the merged section. I created the dialog-data using two programs. First I opened Resource Hacker (a freeware resource editor) and saved the dialog inside my original exe as a binary file. Then I used BINTODB to convert it to a format that can be assembled using masm. After that the only thing left was to change DialogBoxParam to DialogBoxIndirectParam and pass it a pointer to the dialog-data-byte-array.

Edit: Fixed the alignment problem.
Posted on 2003-08-20 14:54:11 by Delight
I get the standard 'improperly linked' message on Win98SE (under 1kb alignment)
Posted on 2003-08-20 15:46:05 by NaN
Thanks Delight,

"I get the standard 'improperly linked' message on Win98SE (under 1kb alignment)"

I got "C:\TEM\1KBDIALO.EXE file is improperly linked with alignment less than 0x1000.
Fix the error, and then link it it again." on my Windows ME

On my WinXP Pro it doesn't work too
because the section and file alignments are 0x200 i.e. under 0x1000

Regards,
Lingo
Posted on 2003-08-20 20:57:22 by lingo12

I get the standard 'improperly linked' message on Win98SE (under 1kb alignment)

so do I

I think you're useing Win2k ;)
Posted on 2003-08-20 21:29:14 by S.T.A.S.
I thought it was safe to use 512b alignment :confused: It works fine on WinXP Home though.
Posted on 2003-08-21 00:09:59 by Delight
also works on my WinXP Pro SP1. nice :grin:
Posted on 2003-08-21 00:25:20 by TBD
This thing in C++ would cost 40k, in VB maybe 16k and in Delphi 200k :eek: , though i like delphi cause it compiles to windows native :grin:

running under Winnt 4.0 SP6
Posted on 2003-08-21 05:22:14 by Ranma_at
Works fine on Win2K SP4
Posted on 2003-08-21 05:24:25 by donkey
doesn't work on winme either, but then again w9x doesn't require any imports.

Originally posted by Ranma_at
in Delphi 200k :eek:


you can do much less, see this attach
Posted on 2003-08-21 07:32:42 by drizz

you can do much less, see this attach


Text1.Text:= "I dont see the attach, and i ve uninstalled Borlands Delphi 6,"
maybe the attach got too big ? :tongue:
Posted on 2003-08-21 07:54:54 by Ranma_at

This thing in C++ would cost 40k, in VB maybe 16k and in Delphi 200k


In VB = 16 K + 1409 K :grin:
Posted on 2003-08-21 08:30:35 by pelaillo
Originally posted by Ranma_at
maybe the attach got too big ? :tongue:

its actually 7kb zip (with binaries and src)

it seems i can't attach :stupid:
Posted on 2003-08-21 08:47:50 by drizz
You could get it down to 984 bytes by using /align:4 ;)
I guess files aligned on <0x1000 run on NT-based systems only.

Anyway, your example compiles to a 1024 bytes long exe even without using /align switch (ie. using standard alignment)
Posted on 2003-08-21 10:27:23 by Morris
cool :grin:
Posted on 2003-08-21 10:37:32 by Delight
This thing in C++ would cost 40k, in VB maybe 16k and in Delphi 200k , though i like delphi cause it compiles to windows native


Delphi 200K because you are using the VCL.
I dont use the VCL and my exe size is 8KB minimum =)
Delphi produces smaller executables than VC++
Posted on 2003-08-21 11:10:08 by maCo
I don't think Delphi can create smaller executables than 8-9kB, but I have seen 1kB examples written in VC++
Posted on 2003-08-21 11:12:10 by Delight
I dont know how to make the VC++ exe smaller than delphi.
but I wrote the same program on both products and Delphi6 = 8KB and VC++ = 20KB
Posted on 2003-08-21 11:20:46 by maCo
Posted on 2003-08-21 11:22:26 by Delight
Thank you.
BTW, nice smaller 1K exe, it works on my XP :alright:
Posted on 2003-08-21 11:24:42 by maCo
VC++ exes compiled with msvc++ are as small as MASM exes. All you have to do is disable incremental linking (under Projects--> Settings), add "msvcrt.lib" into the set of linked libs, and then tell the linker to merge the sections via a #pragma, and your hello world msgboxes will be 1kb (1024 bytes actually) :). Also, make sure you are not using MFC...

Delphi 6 using VCL is around 430k (somewhere around there?), and using CLX is a bit smaller, but that stills beat 2meg runtimes, plus it's 4x smaller if you think of it. And yet still, w/o using VCL, Delphi executables are smaller than VB ones :P (did i mention VB has the crappiest syntax/structure i've ever seen? :tongue: )

i'm into the small-exe hype...so if anybody needs an example, i'll be happy to post one :)
Posted on 2003-08-21 11:28:02 by Drocon