Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Program entry point question

Reply
Thread Tools

Program entry point question

 
 
Angus
Guest
Posts: n/a
 
      04-25-2010
If I want to write a text based C program I use int main etc as my
program entry point. But if I want to write for aexample a GUI
application for some platform then I would use a different entry point
- eg WinMain for MS Windows.

I had a look in crt0.c file included with my compiler and the code
calls mainCRTStartup or WinMainCRTStartup dependent on some defines.
Presumably This is all controlled by defines you setup in your
project?

But why can we not use main for these 'other' program types?
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      04-25-2010
On 25 Apr, 21:09, Angus <(E-Mail Removed)> wrote:
> If I want to write a text based C program I use int main etc as my
> program entry point. *But if I want to write for aexample a GUI
> application for some platform then I would use a different entry point
> - eg WinMain for MS Windows.
>
> I had a look in crt0.c file included with my compiler and the code
> calls mainCRTStartup or WinMainCRTStartup dependent on some defines.
> Presumably *This is all controlled by defines you setup in your
> project?
>
> But why can we not use main for these 'other' program types?


ask Microsoft! I'm afraid the details of this are all very OS
specific. You nedd to ask your question on a Microsoft programming
group. I've found this one helpful

comp.os.ms-windows.programmer.win32

and check out MSDN
 
Reply With Quote
 
 
 
 
bartc
Guest
Posts: n/a
 
      04-25-2010

"Angus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If I want to write a text based C program I use int main etc as my
> program entry point. But if I want to write for aexample a GUI
> application for some platform then I would use a different entry point
> - eg WinMain for MS Windows.
>
> I had a look in crt0.c file included with my compiler and the code
> calls mainCRTStartup or WinMainCRTStartup dependent on some defines.
> Presumably This is all controlled by defines you setup in your
> project?
>
> But why can we not use main for these 'other' program types?


For Win32, you have a choice of WinMain() or main(). This can be for console
or GUI programs.

--
Bartc

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-25-2010
Angus <(E-Mail Removed)> writes:
> If I want to write a text based C program I use int main etc as my
> program entry point. But if I want to write for aexample a GUI
> application for some platform then I would use a different entry point
> - eg WinMain for MS Windows.
>
> I had a look in crt0.c file included with my compiler and the code
> calls mainCRTStartup or WinMainCRTStartup dependent on some defines.
> Presumably This is all controlled by defines you setup in your
> project?
>
> But why can we not use main for these 'other' program types?


A quick Google search for "WinMain" shows that it has a substantially
different set of parameters than the C standard main() function.
If you're interested in the details, the first Google hit for
WinMain has what appears to be a good description.

To use main() for such programs, the system would have to provide
another mechanism for obtaining that information. Microsoft apparently
decided it would be more convenient to provide a different entry point.

Other systems may have similar considerations. (Unix-like systems
usually don't, because C and Unix were developed together.)

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      04-25-2010
Angus wrote:

> If I want to write a text based C program I use int main etc as my
> program entry point. But if I want to write for aexample a GUI
> application for some platform then I would use a different entry point
> - eg WinMain for MS Windows.


The reason for that is that MS's APIs are poorly designed, in order to lead the clueless
newbie to believe that writing windows apps is some sort of strangely magical act.


<snip/>
> But why can we not use main for these 'other' program types?


But we can and we do. For example, let's take Qt. It's an API which is well designed and
puts in shame any of MS's attempts at a GUI API. Yet, it relies on a main() function which
may be similar to the following (incomplete) code:

<code>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow mainWin;
mainWin.show();

return app.exec();
}
</code>
 
Reply With Quote
 
Uno
Guest
Posts: n/a
 
      04-26-2010
Keith Thompson wrote:
> Angus <(E-Mail Removed)> writes:
>> If I want to write a text based C program I use int main etc as my
>> program entry point. But if I want to write for aexample a GUI
>> application for some platform then I would use a different entry point
>> - eg WinMain for MS Windows.
>>
>> I had a look in crt0.c file included with my compiler and the code
>> calls mainCRTStartup or WinMainCRTStartup dependent on some defines.
>> Presumably This is all controlled by defines you setup in your
>> project?
>>
>> But why can we not use main for these 'other' program types?

>
> A quick Google search for "WinMain" shows that it has a substantially
> different set of parameters than the C standard main() function.
> If you're interested in the details, the first Google hit for
> WinMain has what appears to be a good description.
>
> To use main() for such programs, the system would have to provide
> another mechanism for obtaining that information. Microsoft apparently
> decided it would be more convenient to provide a different entry point.
>
> Other systems may have similar considerations. (Unix-like systems
> usually don't, because C and Unix were developed together.)
>


Using proper MS tools, the entry point is trivial, literally.

I spent the first 15 years on the MS bandwagon, and I think open source
is the new juggernaut.

C pretends not to know anything about filehandles, so the WinMain call
is outside C's purview. When I first questioned Keith along these
lines, I was amazed to find out how much my MSVC4++ resembled his ISO C.

Cheers,
--
Uno
 
Reply With Quote
 
spinoza1111
Guest
Posts: n/a
 
      04-26-2010
On Apr 26, 8:45*am, Uno <(E-Mail Removed)> wrote:
> Keith Thompson wrote:
> > Angus <(E-Mail Removed)> writes:
> >> If I want to write a text based C program I use int main etc as my
> >> program entry point. *But if I want to write for aexample a GUI
> >> application for some platform then I would use a different entry point
> >> - eg WinMain for MS Windows.

>
> >> I had a look in crt0.c file included with my compiler and the code
> >> calls mainCRTStartup or WinMainCRTStartup dependent on some defines.
> >> Presumably *This is all controlled by defines you setup in your
> >> project?

>
> >> But why can we not use main for these 'other' program types?

>
> > A quick Google search for "WinMain" shows that it has a substantially
> > different set of parameters than the C standard main() function.
> > If you're interested in the details, the first Google hit for
> > WinMain has what appears to be a good description.

>
> > To use main() for such programs, the system would have to provide
> > another mechanism for obtaining that information. *Microsoft apparently
> > decided it would be more convenient to provide a different entry point.

>
> > Other systems may have similar considerations. *(Unix-like systems
> > usually don't, because C and Unix were developed together.)

>
> Using proper MS tools, the entry point is trivial, literally.
>
> I spent the first 15 years on the MS bandwagon, and I think open source
> is the new juggernaut.


You got that right. Free stuff made by willing, happy slaves fo de
corporation, wif de uppity slaves who talk back "banned"? Sho' nuff,
boss. The ruling class did NOT intend to create a class of highly
educated programmers able to master complex systems and get paid,
since such men and women would then turn around and start questioning
multinational capitalism. Even Bill Gates wised up.

Therefore, the level of programming skill today (as seen in this
newsgroup, especially in Peter Seebach's Coding Horrors) is abominable
by design.
>
> C pretends not to know anything about filehandles, so the WinMain call
> is outside C's purview. *When I first questioned Keith along these
> lines, I was amazed to find out how much my MSVC4++ resembled his ISO C.


As Dave Hansen told me at Princeton, Microsoft and IBM programmers can
be just as smart as programmers in the DEC/unix/Linux tradition. The
regs here think they're slick because they use Linux.
>
> Cheers,
> --
> Uno


 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      04-26-2010
Uno <(E-Mail Removed)> writes:
> Keith Thompson wrote:

[SNIP - stuff about the GUI program entry point in windows]
> Using proper MS tools, the entry point is trivial, literally.


Using proper Unix tools, the entry point is trivial too. Trivial,
and the same as the entry point if you were not writing a GUI
program. I think that makes it even more trivial, personally.

> I spent the first 15 years on the MS bandwagon, and I think open
> source is the new juggernaut.


Nope, MS is still the lumbering smelly thing.

> C pretends not to know anything about filehandles, so the WinMain call
> is outside C's purview.


MSVC knows nothing about 'filehandles' either. If you meant 'file handles',
then taking 'thing handle' as the term for an opaque type which carries
enough information for another agent to operate on a unique object of
type 'thing', then C knows as much about file handles as any other
language, and represents them with the C type FILE*.

Which has anything to do with WinMain, so I can't see any logic in
your sentence at all.

WinMain is outside C's purview precisely because it's not within
C's purview. Pretending that it's because of some single arbitrary
property completely unrelated to WinMain's definition is a wild
misdirection.

> When I first questioned Keith along these
> lines, I was amazed to find out how much my MSVC4++ resembled his ISO
> C.


I'm not sure you questioned Keith cogently, and likewise doubt that
you'd have understood his response, given the above.

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      04-26-2010
On 26 Apr, 01:45, Uno <(E-Mail Removed)> wrote:
> Keith Thompson wrote:
> > Angus <(E-Mail Removed)> writes:


<snip>

> I spent the first 15 years on the MS bandwagon, and I think open source
> is the new juggernaut.


rolls over people and crushes them to death?


> C pretends not to know anything about filehandles, so the WinMain call
> is outside C's purview.


duh? What have filehandles got to do with WinMain()?

MSDN:
int WINAPI WinMain(
__in HINSTANCE hInstance,
__in HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine,
__in int nCmdShow
);

>*When I first questioned Keith along these
> lines, I was amazed to find out how much my MSVC4++ resembled his ISO C.


it's not "his ISO C" It's ISO's. Microsoft are actually quite
conforming (to an older standard) if you press the right buttons.

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      04-26-2010
Angus a écrit :
> If I want to write a text based C program I use int main etc as my
> program entry point. But if I want to write for aexample a GUI
> application for some platform then I would use a different entry point
> - eg WinMain for MS Windows.
>
> I had a look in crt0.c file included with my compiler and the code
> calls mainCRTStartup or WinMainCRTStartup dependent on some defines.
> Presumably This is all controlled by defines you setup in your
> project?
>
> But why can we not use main for these 'other' program types?


You can use main() for GUI programs, and Microsoft has explicitely mentioned this fact since at
least windows 95, when win32 appeared. The only difference in a GUI program and a console program is
a bit set or unset in the executable that tells the program loader to open a console for it or not.

All the answers you got in this goup are wrong, and do not consider this fact either because the
people answering here are ignorants of Microsoft windows conventions, or because they do not like
Microsoft, that they consider the evil empire.

This bit in the executable will be set by your LINKER, not by a "define" or whatever in the crt0
code. The linker accepts a command line option to set or not this bit. Read the documentation of
your linker and you will find it.

All the console programs have full access to ALL GUI functions: they can open windows, close
windows, use sound, display video, you name it. All GUI programs can use a console by forcing the
system to open one with AllocConsole().
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
how to mimik a main() function to start a program with entry point? krishnakant Mane Python 3 01-20-2007 07:24 PM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
Form field entry directs to diff URLs based on entry? AtomicBob HTML 14 05-02-2006 07:07 AM
Clear ATM0.1 point-to-point entry. AM Cisco 2 02-04-2005 10:38 AM



Advertisments