very small win32 programs with vc++.

Started by
24 comments, last by trigger 22 years, 9 months ago
hi all! just some days ago i compiled a program with an empty WinMain function. *shock* totally 24kb exe file only for an empty WinMain program!? after asking on irc i found out that there are some helpfull linker settings that dont linke the not needed stuff. so the exe file shrinked from 24kb to 16kb. when i use upx with the 16kb version i can get the file size down to ~4kb ! the only problem is that i cant really understand how this linker options work! is there anybody out who can explain them to me!? i also got, that when you use that linker option you have to specify the wanted libs or dlls manually. anybody out there who can tell me wich libs are important and why they are???? so you see that i am really interested in how it works and not only in using some linker options somebody told me to use. best regards trigger
http://trigger.xenyon.net/
Advertisement
Look up a function on MSDN. At the end of every document function, it tells you what header the prototype is contained and what lib is required.
well, that wasn''t my question!

i need informations about the following libs and why i have to link them:

kernel32.lib user32.lib gdi32.lib opengl32.lib msvcrt.lib

for example kernel32 or user32. i think that they arent used for any function but have to be used for a win23 programm. and saying to search the msdn is a very bad answer to this question. searching the internet would be faster. msdn is only a reference. but this is another topic. you guys should know that if msdn really is that good, nobody would need books on programming! hope you got that

best regards
trigger
http://trigger.xenyon.net/
Under the linker options, specify /OPT:REF and /OPT:NOWIN98.

That''ll shave of some of the size. Also, make sure you compile in Release mode.

Now if the size isn''t small enough for you,. you might want to link the C runtime using a DLL. Go to Project->Settings->Compiler->C/C++ and select the Multithreaded DLL.

That''ll bring your basic windows app down to 4 KB.

Now for some advice. Don''t ever use UPX (or any executable packer). Never EVER. Its bad. It makes your exe smaller (by up to 75%) but it makes the programs memory requirement jump up to 10 times more (about 1000%)!!! That''s not worth it. I''ve seen it happen to my programs. Just look at your program memory usage under a program lik Win2k Task Manager or Norton Utilities System Info.

==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
well, thanx for the first real reply!

>Now if the size isn''t small enough for you,. you might want to
>link the C runtime using a DLL. Go to
>Project->Settings->Compiler->C/C++ and select the Multithreaded
>DLL.

using the c runtime using a dll!? doesnt this mean that the dll has to be in the system folder?? i heared that only windows 98 and higher has this runtime. win95 wont work! is that right?

later

http://trigger.xenyon.net/
Go here:

http://msdn.microsoft.com/msdnmag/issues/01/01/hood/hood0101.asp

Read.

Enjoy.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

thanx for all!

i really enjoyed reading the text :D !
Add this to yer main .c file, it will
not add in all the useless windows
stuff that it doesnt need. but this
does require you to specifically add
windows includes...

#define WIN32_LEAN_AND_MEAN 
That just speeds up the compiler time (if at all). It doesn''t reduce the exe size, unless of course, my copy of MSVC is broken.

==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Actually, it will shrink the executable size a little bit, but usually since the exe is a multiple of 4Kb, you won''t notice any size change (and also because the compiler does optimize most of it out of the final exe), unless you include functions that are part of the non lean and mean versions. If you do define win32_lean_and_mean, certain header files are not built in, such as windowsx.h.

This topic is closed to new replies.

Advertisement