#### Archived

This topic is now archived and is closed to further replies.

# very small win32 programs with vc++.

This topic is 6222 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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
>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

##### Share on other sites
Go here:

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

Enjoy.

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

##### Share on other sites
thanx for all!

i really enjoyed reading the text :D !

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
Rutin
26
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002086
×