News for hackers. Stuff that matters.
Re:Microsoft introduces Universal Windows apps by dragontamer on Wednesday April 02, 2014 @03:38PM (#7518355)
What you point out is an _abstraction_ that compilers include as part of their kits.

You claim to be a low-level programmer who understands C. The truth is right in front of you. Decompile those programs, look at their symbol tables. Notice, every Win32 program starts at WinMain, called with the arguments that I listed above.

Come back when you've done this simple exercise. Realize, WinMain is the _true_ starting point of "C Programs" in Windows. The rest are compiler abstractions.

http://msdn.microsoft.com/en-us/library/windows/desktop/ff38... >>> How does the compiler know to invoke wWinMain instead of the standard main function? What actually happens is that the Microsoft C runtime library (CRT) provides an implementation of main that calls either WinMain or wWinMain.

Re:Microsoft introduces Universal Windows apps by barrkel on Wednesday April 02, 2014 @03:52PM (#7518465)
The true starting point for PE executables is AddressOfEntryPoint in the PE header, with a few parameters pushed on the stack. WinMain is a compiler abstraction; it is not looked up by name.

You can't code in a high-level language like C without working with abstractions. Whether you look at the main() level or the WinMain() level, there will still be library initialization hooks running before your end-user code gets to run.

Re:Microsoft introduces Universal Windows apps by dragontamer on Wednesday April 02, 2014 @03:59PM (#7518505)
I'm gonna upvote your comment as you are one of the few people in YCombinator who seems to know what they're talking about. Good job catching that, and you're right. The PE Header contains the entry point. (And the MZ Header is potentially a 2nd entry point left in for DOS Compatibility purposes)

The rest of the people here talking as if C is some sort of ultra-portable magic language need to learn about the low level details that differ between OSes.

My primary point remains however, the easiest and most straightforward way to interface with Windows libraries is through C++ and C#. Even C itself is a high-level language built on top of abstractions built by compilers and linkers.

Re:Microsoft introduces Universal Windows apps by sdkmvx on Wednesday April 02, 2014 @03:53PM (#7518474)
Show me where in the ANSI standard it says this is illegal. Implementation details do not matter. The Microsoft C compiler will compile a ANSI C89-conforming program into a runnable executable on Windows. The rest is undefined.

And while we're on implementation details, please note that most UNIX platforms do not start at main either. Most platforms include some soft of crt0 that must be linked which contains the real entry point. The dynamic linker will also run code prior to main.

But the C standard only defines what the environment looks like when execution begins and makes no statement on what might run before or how the program got into memory in the first place.

Re:Microsoft introduces Universal Windows apps by makomk on Wednesday April 02, 2014 @05:03PM (#7518988)
Come to think of it, I don't think I've used any platform where main() is the real entry point to the executable. On Linux the real entry point is _start, all of the bare-metal embedded stuff I've touched does a whole bunch of hardware setup in crt0 before it calls main(), etc...
Re:Microsoft introduces Universal Windows apps by astrange on Wednesday April 02, 2014 @06:36PM (#7519546)
main() is the entry point function in newer OS X versions. Why ship crt0 in everything when you can put it in dyld?
Re:Microsoft introduces Universal Windows apps by derefr on Wednesday April 02, 2014 @08:32PM (#7520048)
crt0 would still get linked into static binaries in OSX, I presume.
Re:Microsoft introduces Universal Windows apps by nknighthb on Wednesday April 02, 2014 @09:49PM (#7520401)
Re:Microsoft introduces Universal Windows apps by craigching on Wednesday April 02, 2014 @04:01PM (#7518523)
> Realize, WinMain is the _true_ starting point of "C Programs" in Windows

Actually I do know that, but you simply said "int main() blah blah blah" doesn't "work" (to quote you there). If you're going to require me to be precise, maybe you should look in the mirror first.

Re:Microsoft introduces Universal Windows apps by shadowwolf007 on Wednesday April 02, 2014 @04:05PM (#7518555)
Asm output from a c program that prints hello world to the screen. You can figure out the other sections I'm sure.

No win main or other similar concepts here and built using vs2012.

Microsoft (R) COFF/PE Dumper Version 11.00.61030.0 Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file consoleapplication6.exe

File Type: EXECUTABLE IMAGE

_main: 00401000: 68 48 20 40 00 push offset ??_C@_0M@KIBDPGDE@Hello?5world?$AA@ 00401005: FF 15 00 20 40 00 call dword ptr [__imp__puts] 0040100B: 83 C4 04 add esp,4 0040100E: 33 C0 xor eax,eax 00401010: C3 ret

  Summary

        1000 .rdata
        1000 .reloc
        1000 .rsrc
        1000 .text
Re:Microsoft introduces Universal Windows apps by voltagex_ on Wednesday April 02, 2014 @08:24PM (#7520017)
I've tried to do programs with /nostdlib before, how did you implement the startup and shutdown functions that are required?
Re:Microsoft introduces Universal Windows apps by shadowwolf007 on Thursday April 03, 2014 @11:29AM (#7523490)
Sorry about that I didn't see your reply! Because I have to use phone it's challenging to type out all I did. While I achieved it, I wouldn't say it's sensible or easy!

Anyway, you have to turn off c++, c++ exceptions, security checks in compiler options. In linker set the entry point to main and turn off error reporting. From there it's finding the right lib which is dependent on arch, etc.

To be honest it's not worth doing. I only knew of it because I had to patch a vs2010 exe to run on windows 2000.