include/SDL_main.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Jun 2013 22:44:49 -0700
changeset 7335 13b67be8e3af
parent 7281 cd5516b9263d
child 7653 9a0e274b8aa7
child 8477 ad08f0d710f3
permissions -rw-r--r--
Not using SDLmain on Windows is just fine, don't fail the initialization if the program implements WinMain() and then doesn't call SDL_SetMainReady().
This broke Steam's Big Picture game controller support.

I also added some more documentation so people know why main() is overridden on various platforms.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@0
    21
slouken@0
    22
#ifndef _SDL_main_h
slouken@0
    23
#define _SDL_main_h
slouken@0
    24
slouken@1356
    25
#include "SDL_stdinc.h"
slouken@1356
    26
slouken@3407
    27
/**
slouken@3407
    28
 *  \file SDL_main.h
slouken@7191
    29
 *
slouken@3407
    30
 *  Redefine main() on some platforms so that it is called by SDL.
slouken@3407
    31
 */
slouken@0
    32
slouken@5320
    33
#ifndef SDL_MAIN_HANDLED
slouken@7335
    34
#if defined(__WIN32__)
slouken@7335
    35
/* On Windows SDL provides WinMain(), which parses the command line and passes
slouken@7335
    36
   the arguments to your main function.
slouken@7335
    37
slouken@7335
    38
   If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
slouken@7335
    39
 */
slouken@7335
    40
#define SDL_MAIN_AVAILABLE
slouken@7335
    41
slouken@7335
    42
#elif defined(__IPHONEOS__)
slouken@7335
    43
/* On iOS SDL provides a main function that creates an application delegate
slouken@7335
    44
   and starts the iOS application run loop.
slouken@7335
    45
slouken@7335
    46
   See src/video/uikit/SDL_uikitappdelegate.m for more details.
slouken@7335
    47
 */
slouken@5320
    48
#define SDL_MAIN_NEEDED
slouken@7335
    49
slouken@7335
    50
#elif defined(__ANDROID__)
slouken@7335
    51
/* On Android SDL provides a Java class in SDLActivity.java that is the
slouken@7335
    52
   main activity entry point.
slouken@7335
    53
slouken@7335
    54
   See README-android.txt for more details on extending that class.
slouken@7335
    55
 */
slouken@7335
    56
#define SDL_MAIN_NEEDED
slouken@7335
    57
slouken@5320
    58
#endif
slouken@7335
    59
#endif /* SDL_MAIN_HANDLED */
slouken@0
    60
slouken@0
    61
#ifdef __cplusplus
slouken@7191
    62
#define C_LINKAGE   "C"
slouken@0
    63
#else
slouken@0
    64
#define C_LINKAGE
slouken@0
    65
#endif /* __cplusplus */
slouken@0
    66
slouken@3407
    67
/**
slouken@3407
    68
 *  \file SDL_main.h
slouken@3407
    69
 *
slouken@3407
    70
 *  The application's main() function must be called with C linkage,
slouken@3407
    71
 *  and should be declared like this:
slouken@3407
    72
 *  \code
slouken@3407
    73
 *  #ifdef __cplusplus
slouken@3407
    74
 *  extern "C"
slouken@3407
    75
 *  #endif
slouken@3407
    76
 *  int main(int argc, char *argv[])
slouken@3407
    77
 *  {
slouken@3407
    78
 *  }
slouken@3407
    79
 *  \endcode
slouken@0
    80
 */
slouken@3407
    81
slouken@7335
    82
#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
slouken@7191
    83
#define main    SDL_main
slouken@5320
    84
#endif
slouken@0
    85
slouken@3407
    86
/**
slouken@3407
    87
 *  The prototype for the application's main() function
slouken@3407
    88
 */
slouken@0
    89
extern C_LINKAGE int SDL_main(int argc, char *argv[]);
slouken@0
    90
slouken@0
    91
slouken@0
    92
#include "begin_code.h"
slouken@0
    93
#ifdef __cplusplus
slouken@0
    94
extern "C" {
slouken@0
    95
#endif
slouken@0
    96
slouken@7281
    97
/*
slouken@7281
    98
 *  This is called by the real SDL main function to let the rest of the
slouken@7281
    99
 *  library know that initialization was done properly.
slouken@7281
   100
 *
slouken@7281
   101
 *  Calling this yourself without knowing what you're doing can cause
slouken@7281
   102
 *  crashes and hard to diagnose problems with your application.
slouken@7281
   103
 */
slouken@7281
   104
extern DECLSPEC void SDL_SetMainReady(void);
slouken@7281
   105
slouken@5320
   106
#ifdef __WIN32__
slouken@5320
   107
slouken@3407
   108
/**
slouken@3407
   109
 *  This can be called to set the application class at startup
slouken@3407
   110
 */
slouken@1895
   111
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
slouken@1895
   112
                                            void *hInst);
slouken@1466
   113
extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
slouken@1895
   114
slouken@5320
   115
#endif /* __WIN32__ */
slouken@5320
   116
slouken@5320
   117
slouken@0
   118
#ifdef __cplusplus
slouken@0
   119
}
slouken@0
   120
#endif
slouken@0
   121
#include "close_code.h"
slouken@0
   122
slouken@0
   123
#endif /* _SDL_main_h */
slouken@1895
   124
slouken@1895
   125
/* vi: set ts=4 sw=4 expandtab: */