.com vs .exe

Started by
27 comments, last by DarkEmpire 21 years, 9 months ago
Hi, Is it possible to create a ".com" executable with Visual C++ 6 ? or can we create only ".exe" executable ? Are ".com" smaller than ".exe" ? Are there advantages ? Thanks for your help
Advertisement
.COM''s have max size (data & code) of 64k.
Also I don''t think you can do windows programming with a COM file, although I could be wrong there.

I''m pretty sure MSVC doesn''t make .COM files.
If I recall correctly, in COM files you have to use a single segment (CS=DS=ES=SS). This segment has to be < 64K.

Therefore COM files must be written using assembly language, as most compilers use multiple segments. At least, I have never seen a high-level compiler generate code like this (I do remember a BAT2COM utility though).

As a result, I think that COM files have to be 16-bit code (1 16-bit segment...no flat memory model). If this is true, then there is no way MSVC++ can generate them, as VC++ only makes 32-bit Windows EXE files.

And don't let COMMAND.COM fool you (it's actually an EXE in newer versions).

--TheMuuj

[edited by - themuuj on June 25, 2002 5:39:43 PM]
--TheMuuj
Q: Is it possible to create a ".com" executable with Visual C++ 6 ?
A: Not unless it is an undocumented feature. You would more likely use an assembler (e.g. masm)

Q: Are ".com" smaller than ".exe" ? Are there advantages ?
A: By definition, com files are 64kB max... runtime stack and heap included. AFAIK there''s no big advantage anymore.


Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
In fact, i try to find tips to have the smallest executable as possible.

In fact, i searched on google and developpment websites, how to create very small exe with VC6 but i did not find the solution.

In fact, with linker options i use, the smallest empty project executable i succeeded to create is a 517 bytes one... But i think it s very big for a application that does nothing ...

Have you got tips to help me ?

Try compressing exe with UPX.
---visit #directxdev on afternet <- not just for directx, despite the name
I tried, and UPX did not succeed to compress it
Intersting trick, you can rename an EXE to a COM and it will still work exactly the same. This is actually usefull because there are some viruses that will make it impossible to run EXE''s (including virus scanner), so you rename the EXE to COM.
You can also use this trick on some NT based systems that have REGEDIT locked. if you rename REGEDIT.EXE to REGEDIT.COM you can usually get around the lockout. Of course, it the sysadmins are smart enough, they''ll lock renaming REGEDIT.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

"In fact"? What, you think they''re lying to you. Like 3 people said the same thing. One of them has to be right. Or maybe I''m lying...

Even if a program does nothing, it has to link to certain libraries in order for it to even have a minimal amount of capability (for instance, starting up through a main function). "In Fact", if you use the MFC libraries, your program will ALWAYS be huge. This has to do with all the background linking it does. 517 bytes for a program seems about small even if you link to at least a standard library (iostream). When you start using DirectX or OpenGL or any nice API out there (Graphics or whatever), that size will substantially grow no matter what. If you wanted to enter one of those demo scene competitions the way to go is by creating your own librarys, using procederal geometry and textures, and compressing your .exe. A .com file is not a solution to anything anymore really (''cept for viruses or maybe drivers).

What help do you want? Their answer was no you can''t make com files in Visual C++ 6 and they are limnited to 64k...

Btw, with just a void main() {} in Visual C++ 7.0 with a retail build optimized for size, my file was 20.5 KB. Good job with your 517 bytes.



"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com
quote:Original post by DarkEmpire
In fact, i searched on google and developpment websites, how to create very small exe with VC6 but i did not find the solution.

At MSDN search on "tinycrt" - Matt Pietrek has written three columns on the subject over the years. Also take a look here: http://www.hailstorm.net/papers/smallwin32.htm. There is an article "Small Windows Executables" at CFXWeb with details in Hugi21 - that is all asm though.


quote:Original post by DarkEmpire
In fact, with linker options i use, the smallest empty project executable i succeeded to create is a 517 bytes one... But i think it s very big for a application that does nothing ...


That''s pretty damn small if you ask me. Especially considering the file alignment sets the PE file headers to 512 bytes. If you''re getting down to that size, then you are breaking new ground, I think and you''re not likely to find much more help on the www.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement