Archived

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

.com vs .exe

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
.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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
"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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
quote:
Original post by DarkEmpire
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


Advantages: Small/Simple/Compact (and no EXE header)

How to have .COM?
1. Try using Turbo C/C++ from Borland (free download)
2. and have the memory model set to TINY.
3. build the .EXE file
4. run the EXE2BIN command (included in early version of DOS)
5. rename the .BIN file to .COM file.
6 you''re done!

*Note*: I believe you can''t create a .COM if you have any recursive functions.... uh... can''t recall my memory.

Share this post


Link to post
Share on other sites
quote:
Original post by Leadorn
Is 64 segments only in 16 realmode? Pmode one large memory adress no segment?


yep, 64k segmented architecture is available on Intel 16bit Platform (8086/8088 anyone? )... and is in realmode. I believe .COM file contains pure instruction codes.

Share this post


Link to post
Share on other sites
quote:
Original post by Leadorn
Is 64 segments only in 16 realmode? Pmode one large memory adress no segment?


yep, 64k segmented architecture is available on Intel 16bit Platform (8086/8088 anyone? )... and is in realmode. I believe .COM file contains pure instruction codes.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
@TheMuuj: that bat2com program might of been turbobat: http://www.simtel.net/pub/pd/40684.html

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
@TheMuuj: that bat2com program might of been turbobat: http://www.simtel.net/pub/pd/40684.html


I''m pretty sure it was called ''bat2com.'' I think I got it from TSL (The Software Labs), back when I used to order shareware disks from them.

I also think there is an bat2exe and a com2exe.

It''s a moot point, though, as these utilities are pointless today.

--TheMuuj

Share this post


Link to post
Share on other sites
Too bad real COM files don''t have any DLL imports. DOS has been obsolete for over 5 years, just be happy you have powerful computers and operating systems to work with instead of trying to save kilobytes by using old technology

Share this post


Link to post
Share on other sites
quote:
Original post by Martee
You misspelled ''over 20 years''


I''m guessing your part of the Windows 95 generation? Windows 3.1 (a shell over DOS) only became widespead at the beginning of the 90s. Even when people where using 3.1 DOS (which 3.1 ran on top of) was still used for almost every game. DOS only died sometime after Windows 95 (August 1995) came out, and even then it was still alive as a good platform for games for some time. So even if you consider the old shell Windows to have somehow made DOS obsolete, that would be 12-13 years at best. Frankly 5 years sounds about right for when mainstream DOS support stopped (around the time good 3D accelerators where making their mark)

Share this post


Link to post
Share on other sites
quote:
Original post by Leadorn
but what about protected mode.

Pmode one large memory adress no segment?



Hmm... I''m not sure about this. I believe they don''t have segment anymore. That''s why we don''t have any problem to allocate one large block (few megs per block from the heap.

Also, which Pmode you are talking about? The one ''implemented'' by DOS4G/W, CWSDPMI..., or our Windows 32bit EXE? I think they work somewhat differently (though almost similar).

Share this post


Link to post
Share on other sites
Er ... you missed my point. I wasn''t talking talking about ''market share'' obselecence, I was talking about ''technological'' obselecence. Since it''s creation in 1981, DOS has always been a poorly designed, technically inept operating system.

And it was a joke. Notice the smiley?

Share this post


Link to post
Share on other sites
I would say that as soon as PCs with 4MB of RAM were commonplace, then DOS was effectively obsolete (with respect to technology). When did OS/2 first come out?

DOS was designed to run on slow systems with very little memory. Over the years it was added to in order to keep up with new PC technologies (hard disks, extended memory, etc.). In the early days DOS did its job well and nothing more was needed of it. If it had been possible to use Unix effectively on early PCs, I''m sure it would have happened.

And all Windows95 did was extend DOS beyond its lifetime. Therefore, I believe that even Windows95 was also obsolete from day one. So was Windows 98. WindowsME was so obsolete it wasn''t even funny.

This doesn''t mean they were worthless (except for WindowsME :-)).

The use of technology lags behind the development of technology. In DOS''s case, this lag was exaggerated.

--TheMuuj

Share this post


Link to post
Share on other sites
OK. I will explain protected mode. There are not three or four different types of PM. There is one type. Windows uses protected mode to create segemnt descriptors for and exe when it starts. Got it now? Try reading about it on the net.

Share this post


Link to post
Share on other sites