• ### Announcements

#### Archived

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

# Should I use main() or WinMain() ?

## Recommended Posts

I''m programming in Win32 MSVC++6.0 and used always WinMain as an entry point. But I can''t resist the idea of making multiplatform apps so I should use main() instead of WinMain(). What is the difference. If I use for example CreateWindow(...), I need the hInstance that is given in WinMain(...). Can I create a window using CreateWindow(...) in main(...) and get the hInstance using GetModuleHandle(NULL)? How does multiplatform apps (for example glut library) create window? Also if I make a glut program and add there DirectSound implementation. I think I need the HWND handle to create DirectSound, but how can I get it out from glut window?

##### Share on other sites
if it''s cross platform you want, try a console app instead of a win32 app. in win32 if you want a window you pretty well have to use the built in WinMain. unless you use something cross platform like glut.

HHSDrum@yahoo.com

##### Share on other sites
quote:
Original post by stefu
I''m programming in Win32 MSVC++6.0 and used always WinMain as an entry point. But I can''t resist the idea of making multiplatform apps so I should use main() instead of WinMain(). What is the difference.

If I use for example CreateWindow(...), I need the hInstance that is given in WinMain(...). Can I create a window using CreateWindow(...) in main(...) and get the hInstance using GetModuleHandle(NULL)?
How does multiplatform apps (for example glut library) create window?

Also if I make a glut program and add there DirectSound implementation. I think I need the HWND handle to create DirectSound, but how can I get it out from glut window?

When you create Win32 apps, you have to use WinMain. If you don''t, you get a compiler error. Main() is for Console apps. Basicly, WinMain is sort of similar to when you create your Game Loop, it''s part of a the Windows program. It needs to be defined to run. ( I know, I''m not that clear when I try to explain but hey. )...

"And that''s the bottom line cause I said so!"

Cyberdrek
A division of DLC Multimedia

##### Share on other sites
So if I make a Console app, I can''t use any Win32 functions? I can''t use DirectX? How can I create a window in console app?

##### Share on other sites
Ok, I made a simple app that creates a window, using CreateWindow in console app. So it works. Thank me

##### Share on other sites
If you want to make multiplatform apps, what are you doing then with win32 API functions? These only work on, surprise surprise, win32. Not much crossplatform, is it?

If you really want crossplatform apps, develop your progs with crossplatform libraries, like glut. To do the sounds, you''ll have to find another lib, glut and opengl only do gfx.

I use glut myself, not that much because I want multiplatform development, but because I don''t want to learn win32 api. In the dev phase, I use main(), because it allows me to easily print debug messages to the console. When I think it is ready to be tested by other people, I will change main() to WinMain(), just to get rid of the console.

##### Share on other sites
Well, my point was for example to support DirectX in Win32. I know there is OpenAL for sounds. What good they are? I heard tey are scrap? If you know a list of multiplatform libraries, give me the url. Thanks.

##### Share on other sites
You don''t need multiplatform libraries to create cross-platform applications. As long as you have enough abstraction, you should just be able to replace your Win32Sound class with your LinuxSound or MacSound class and compile under those other platforms. Of course, that means you''ll have to learn a different API for each platform, but the chances of a single-person project getting past the tech. demo stage and still being multiplatform are pretty slim anyway (simply because it''s very difficult to keep your code cross-platform, plus I personally don''t think it''s worth the trouble).

Note that I said "pretty slim" and "very difficult", not "zero" and "impossible". It is of course possible for a single person to write a complete multiplatform game, but I''ve never heard of anyone actually doing it to completion.

##### Share on other sites
Just want to point aout there is a Main() in the win32 Libs . Anyway the easiest way to make cross platform Apps including sound , input etc use something like SDL or ClanLib. SDL will let you use DX acceleration , and OGL app in windows , and OGL in Linux , Beos etc.

##### Share on other sites
I just want to reassert what Dean said. Abstraction! It is what makes C++ and OOP so great.

Using truly crossplatform libraries will cut down on development time a little bit, maybe. But at the cost of performance. You will never get the speed from cross-platform libraries that you will from dependent libraries. There is a reason the are platform dependent i.e.: They use specific features of the platform in the way they were meant to be used.

Normally APIs are not a whole lot different between platforms. And they should take up only a small portion of the code you write for your game. If you encapsulate sound, graphics and input in your own classes, and only call API methods from those classes, it is only a matter of rewriting the wrapper classes to port them to the next platform.

I will tell you from lots of experience that people who write cross-platform applications do not do so using cross-platform libraries. Atleast most don''t. There are a few oddballs who have the hair in the wrong place, but most will use abstraction and then port the platform dependent classes. It''s just a happier marriage that way.

Seeya
Krippy

##### Share on other sites
To get ontopic again:

You can also use WinMain AND main

  int main(int argc, char** argv){ // Blah // ... return 0;}#if defined(_WIN32)int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) return main( __argc, __argv );}#endif

You can also set the entry point symbol (menu Settings -> Link -> Output -> Entry-point symbol) of your program (windows version) to "mainCRTStartup" wich calls main instead of WinMain...

##### Share on other sites
Until about a week ago it was pretty hard to write a cross-platform app that used a GUI. However, Trolltech (www.trolltech.com) have just released their QT cross-platform GUI library for free under windows (it had been free under linux for a while). It compiles under Win32, Linux, Mac OSX, and (I think) BeOS, with NO changes. As far as other cross-platform stuff. I''d go with the SDL (www.libsdl.org) to 2d and image surface stuff, and (of course) OpenGL and GLUT for the 3d stuff.

In summary:
1.) QT (www.trolltech.com) (This thing is Friggin'' Awesome! Check it out!)

2.) SDL (www.libsdl.org) (This also has some simple gross platform GUI libs written on top of it, so you might be able to use those too).

3.) OpenGL (www.opengl.org)

• ### Forum Statistics

• Total Topics
627711
• Total Posts
2978753

• 21
• 14
• 12
• 39