SDL and main()

Hello!

Is there any way to use SDL with an “ordinary” main function now a days-
e.g. main on Linux and WinMain on Windows without having to include
SDL.h in that file so that main gets mangled?

As far as I can see, what is needed is some alternative way to
initialize
SDL without requiring a special main function - maybe an extra argument
to
SDL_Init? Or maybe an SDL_InitMain function or something…

What I need it for is to support SDL in an ML compiler (MLton) without
having to hack the compiler runtime source just to get MLton to use
another
main function. It would be nice to be able to use SDL only by
using API calls :slight_smile:

Any hints, info, plans?

Cheers

http://www.HardcoreProcessing.com

You could just #undef main for Windows. IIRC, the initialization code on
Windows only reopens stdin and stdout so that output is redirected to
stdin.txt and stdout.txt respectively. At least I have been able to do
without SDLmain.lib and everything still worked fine.
Please correct me if I’m wrong…

cu,
NicolaiAm Mittwoch, 1. Mai 2002 20:22 schrieb Anoq of the Sun:

Hello!

Is there any way to use SDL with an “ordinary” main function now a days

e.g. main on Linux and WinMain on Windows without having to include
SDL.h in that file so that main gets mangled?

Nicolai Haehnle wrote:

You could just #undef main for Windows. IIRC, the initialization code on
Windows only reopens stdin and stdout so that output is redirected to
stdin.txt and stdout.txt respectively. At least I have been able to do
without SDLmain.lib and everything still worked fine.
Please correct me if I’m wrong…

Well, I was looking for a more “official” way of doing it - rather
than something which “happens to work because the implementation
happens to only be doing this and that” :slight_smile:

Like making all the usual initialization code from main accessible
from an official API call. Also I was thinking of something which
is supposed to work on all platforms.

Cheers–
http://www.HardcoreProcessing.com

Nicolai Haehnle wrote:

You could just #undef main for Windows. IIRC, the initialization code on
Windows only reopens stdin and stdout so that output is redirected to
stdin.txt and stdout.txt respectively. At least I have been able to do
without SDLmain.lib and everything still worked fine.
Please correct me if I’m wrong…

This is wrong. DirectInput won’t initialize correctly on some platforms
if you do this. You also need to call SDL_RegisterApp() with the module
handle passed to you in WinMain().

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Sam Lantinga wrote:

This is wrong. DirectInput won’t initialize correctly on some platforms
if you do this. You also need to call SDL_RegisterApp() with the module
handle passed to you in WinMain().

Is there any “official” / clean way of avoiding:

#include <SDL.h>

main

?

I know I asked this earlier - but I still haven’t found any replies…
I’m hoping for a couple of API calls or something…

Or any plans? :slight_smile:

Cheers–
http://www.HardcoreProcessing.com