Advertisement

main() in win32?

Started by September 28, 2000 11:19 PM
5 comments, last by A. Buza 24 years, 3 months ago
I know something like this was posted here before, but damned if I can find it... Anyway, is it possible to use main() instead of WinMain() in win32 applications? Not console apps of course, but full-blown win32 things?
nope.

Does that answer your question? =)

That answer comes from Microsoft''s "Programming Windows: Fifth Edition" by Charles Petzold, the codex of Windows programming.

You can''t use a different name than WinMain even if you define the return type and parameters the same way. That''s because your compiler and its libraries look for a function labeled "WinMain" to use as an entry point, just like the old main().
Advertisement
Wow, it''s not often that Petzold is wrong, but...

the /ENTRY linker option does exactly what A. Buza is asking.

search for /ENTRY in MSDN.
You could always just hide away your winmain function someplace and -

return main(......);

from your winmain function.
"It's obvious isn't it Miller? Curiosity killed these cats!"
quote: Original post by JonStelly

Wow, it's not often that Petzold is wrong, but...

the /ENTRY linker option does exactly what A. Buza is asking.

search for /ENTRY in MSDN.


Well I'll be damned, you're right! Maybe they ought to start on a 6th edition, eh?

However, it still has to be defined as the WinMain is defined (parameters, calling convention, etc.). So in that respect it isn't like the main() entry point for console apps.

Edited by - Steel on September 29, 2000 9:25:20 PM
I dont see the problem, guys, the
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,char* cmdline,int showcomand)
{
return MessageBox("Billy, dont write such stupid main()''s");
}
has a big advantage:
you easily find it in the code, because its such a big name.

There is just one thing, exept HINSTANCE, you could put the standart-c-types in

just this boring HINSTANCE, look at the declaration:

#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name

DECLARE_HANDLE(HINSTANCE);

at the end, its just an int, but you cant change it, so MessageBox("BILLY!!!!!",MB_OK|MB_VERY_BIG);
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Advertisement
Actually, main() can be defined as a standard main(int argc, char *argv[])

I didn''t try passing parameters, but I''m gonna guess that it would probably work. Give it a shot and let us know. =)

And sure this isn''t something I''d really suggest, it doesn''t really add anything to the project, but it''s a good reason to start digging into entry-point symbols etc... for someone.

This topic is closed to new replies.

Advertisement