What makes a Windows EXE?

This is a discussion on What makes a Windows EXE? within the Windows Programming forums, part of the Platform Specific Boards category; Is there some special "format" (and if so to what extent) of Win32 EXE:s? Having read a tutorial on creating ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    70

    Question What makes a Windows EXE?

    Is there some special "format" (and if so to what extent) of Win32 EXE:s? Having read a tutorial on creating windows programs (using C) I noticed how many funcs and loops were just the way the had to be in a windows program. That made me thinking - maybe that is what makes a .EXE a windows app rather than the windows-orientation of the compiler??
    Last edited by willkoh; 01-28-2005 at 03:29 PM. Reason: Added mail notice

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,810
    No what makes a window's exe is that you compiled your program on windows. It doesn't matter if you used the win32 api or just plain C. If you just wrote a app in pure c and compiled it on windows then tried to make it "run" on another system it would not work.
    Woop?

  3. #3
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Is there some special "format" (and if so to what extent) of Win32 EXE:s?
    Yes, it's the Portable Executable (PE) format.

    If you just wrote a app in pure c and compiled it on windows then tried to make it "run" on another system it would not work.
    Unless of course the system has an emulator or interpreter of some sort. Like WINE for Linux.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Is there some special "format" (and if so to what extent) of Win32 EXE:s?<<

    Yes.

    Compliments of Matt Pietrek:

    An In-Depth Look into the Win32 Portable Executable File Format.
    Peering Inside the PE: A Tour of the Win32 Portable Executable File Format.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    70
    Some compilers support, in addition to PE, creating something called "native" code. Does this mean the PE format does not contain X86 machine code but rather something read by windows, as opposed to what "native" does? What about creating a native program that uses no windows specific things, would it run on another OS, even if the compiler was for windows? This is supposing it doesn't do anything forbidden by this other OS...
    Last edited by willkoh; 01-28-2005 at 05:07 PM. Reason: Removed "hrm..." in case it's rude in english (in swedish it's a "I-wonder"-noice)

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Some compilers support, in addition to PE, creating something called "native" code. Does this mean the PE format does not contain X86 machine code but rather something read by windows, as opposed to what "native" does?

    compiled code *is* native code (it can be executed directly). Java, on the other hand, is not (it requires an interpreter to run). note that Windows is not limited to X86 processors - others are supported.

    >> What about creating a native program that uses no windows specific things, would it run on another OS, even if the compiler was for windows?

    no, because compiled code targets a specific OS/CPU it must be recompiled for each system. that's what makes languages like Java so popular - pretty much platform independant.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    An executable format is really just OS specific headers and the actual machine code that will be processed by the computer. If you read documentation on a given executable type you will find what a executable file contains other than the actual program itself.

    Many programs need to take into account concepts such as dynamically linking to other processes, being handled under certain OS conditions, etc. The PE format that windows uses is just one type of executable type. An "exe" file won't run on a machine that is expecting an ELF formatted executable, for example.

    That said, other than for the sake of curiosity, unless you are either writing a program, in binary, by hand, or you are writing some sort of compiler, or disassembler, there is really not much reason for you to look too deep into this question for now.

  8. #8
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56
    Perhaps what you are looking for is PE header information?

    I have provided a link to a tutorial on PE file format if this is what is required. I hope this helps.

    PE Header Tutorial
    SpEcIeS

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    70
    unless you are either writing a program, in binary, by hand, or you are writing some sort of compiler, or disassembler, there is really not much reason for you to look too deep into this question for now
    Actually I've wanted very much for long time to make both a compiler and/or operating system, that's why these topics interest me.

    Could anyone explain why .EXEs have to be so large? The common explanation (and I believe this applies to any OS) is that their relative memory access information makes them big. Still, they're not ready for actual execution until the OS has replaced their relative memory references with actual ones for the assigned memory area... So why not just use .COM:s (with their absolute adressing) and adapt it to current conditions (ie replace absolute offset 100h with %AppLoadedAt%+100h)?

  10. #10
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266
    .COM files are a legacy executable format that is just pure binary code. There's nothing in them that designates the 100h code segment offset, it's assumed. Also, they were never designed to exceed 64KB (i.e. a 16-bit segment) in size. This imposes a lot of restrictions on what you can do with them. With 32-bit instructions, 64KB doesn't stretch very far.

    Windows "requires" the use of a format like PE in order to properly import functions (Which ALL Windows programs do, mostly from KERNEL32) and work with a paging memory model. Getting all of these things to work together isn't as easy as you might think.
    Last edited by SMurf; 01-29-2005 at 10:25 AM.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    70
    ...but they can exceed 64k, I read about them in john socha / peter nortons old assembler book. This is without becoming as large as an EXE I think...

    The PE format doesn't seem to contain any machine code, yet a program compiled for one processor might not work on the other... So what's the point? Not the speed of machine code... no independency either...

  12. #12
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> Could anyone explain why .EXEs have to be so large? <<

    EXEs are typically quite "large" because they contain statically linked code to implement portions of the C and/or C++ standard libraries. If you strip all this out, you can have a simple program in a 2KB exe. Have a look at Reduce EXE and DLL Size with LIBCTINY.LIB.

  13. #13
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56
    Reduce EXE and DLL Size with LIBCTINY.LIB
    That is an excellent article and very informative. Thank-you very much anonytmouse
    SpEcIeS

  14. #14
    Registered User
    Join Date
    Jan 2005
    Posts
    70
    It's great if I inadvertently helped people reduce size of their EXEs, but for my part, is mostly about understanding os and compiler technology, and I question things for the sake of understanding. Maybe getting that Code by petzold (or what's his name) will help...

    (ofcourse few people with todays hds and ram size have actual problems with their exes)

  15. #15
    Trolley boy JackGL's Avatar
    Join Date
    Jan 2005
    Location
    UK
    Posts
    15
    Quote Originally Posted by willkoh
    ofcourse few people with todays hds and ram size have actual problems with their exes
    This is beside the point. You cannot afford to become complacent, simply because most users won't have a problem.

    When I used to design websites, I would always aim to make it as simple and cut-down as possible, simply because there were a handful of people that wouldn't be able to download it all in half a second.

    It's hard to beleive, but I still know people who routinely use 28.8kbps internet connections, simply because their phone lines aren't capable of higher bandwidth transmissions.

    It is these people that you must think of when writing software.

    At work, my boss keeps telling us: "Impress one person and they will tell two people, but upset someone and they will tell nine."

    I don't know if it's based on fact or what, but it's good to keep in mind.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. resizing makes child windows blink
    By robig2 in forum Windows Programming
    Replies: 15
    Last Post: 01-14-2008, 03:24 AM
  2. run windows exe
    By munna_dude in forum Linux Programming
    Replies: 3
    Last Post: 10-10-2007, 02:12 AM
  3. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 10:59 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 10:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21