include/SDL_main.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 23 Apr 2019 07:59:31 -0700
changeset 12714 9b7633bd0aa0
parent 12663 73499f0997d9
permissions -rw-r--r--
Use _Exit() when available
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 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@10638
    22
#ifndef SDL_main_h_
slouken@10638
    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
dludwig@8480
    42
#elif defined(__WINRT__)
dludwig@8500
    43
/* On WinRT, SDL provides a main function that initializes CoreApplication,
dludwig@8480
    44
   creating an instance of IFrameworkView in the process.
dludwig@8480
    45
dludwig@8480
    46
   Please note that #include'ing SDL_main.h is not enough to get a main()
dludwig@8531
    47
   function working.  In non-XAML apps, the file,
dludwig@8531
    48
   src/main/winrt/SDL_WinRT_main_NonXAML.cpp, or a copy of it, must be compiled
dludwig@8531
    49
   into the app itself.  In XAML apps, the function, SDL_WinRTRunApp must be
dludwig@8531
    50
   called, with a pointer to the Direct3D-hosted XAML control passed in.
dludwig@8480
    51
*/
dludwig@8480
    52
#define SDL_MAIN_NEEDED
dludwig@8480
    53
slouken@7335
    54
#elif defined(__IPHONEOS__)
slouken@7335
    55
/* On iOS SDL provides a main function that creates an application delegate
slouken@7335
    56
   and starts the iOS application run loop.
slouken@7335
    57
slouken@12659
    58
   If you link with SDL dynamically on iOS, the main function can't be in a
slouken@12659
    59
   shared library, so you need to link with libSDLmain.a, which includes a
slouken@12659
    60
   stub main function that calls into the shared library to start execution.
slouken@12659
    61
slouken@7335
    62
   See src/video/uikit/SDL_uikitappdelegate.m for more details.
slouken@7335
    63
 */
slouken@5320
    64
#define SDL_MAIN_NEEDED
slouken@7335
    65
slouken@7335
    66
#elif defined(__ANDROID__)
slouken@7335
    67
/* On Android SDL provides a Java class in SDLActivity.java that is the
slouken@7335
    68
   main activity entry point.
slouken@7335
    69
slouken@11666
    70
   See docs/README-android.md for more details on extending that class.
slouken@7335
    71
 */
slouken@7335
    72
#define SDL_MAIN_NEEDED
slouken@7335
    73
slouken@11666
    74
/* We need to export SDL_main so it can be launched from Java */
slouken@11666
    75
#define SDLMAIN_DECLSPEC    DECLSPEC
slouken@11666
    76
gabomdq@8833
    77
#elif defined(__NACL__)
gabomdq@8833
    78
/* On NACL we use ppapi_simple to set up the application helper code,
gabomdq@8833
    79
   then wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before 
gabomdq@8833
    80
   starting the user main function.
gabomdq@8833
    81
   All user code is run in a separate thread by ppapi_simple, thus 
gabomdq@8833
    82
   allowing for blocking io to take place via nacl_io
gabomdq@8833
    83
*/
gabomdq@8833
    84
#define SDL_MAIN_NEEDED
gabomdq@8833
    85
slouken@5320
    86
#endif
slouken@7335
    87
#endif /* SDL_MAIN_HANDLED */
slouken@0
    88
slouken@11666
    89
#ifndef SDLMAIN_DECLSPEC
slouken@11666
    90
#define SDLMAIN_DECLSPEC
slouken@11666
    91
#endif
slouken@11666
    92
slouken@3407
    93
/**
slouken@3407
    94
 *  \file SDL_main.h
slouken@3407
    95
 *
slouken@3407
    96
 *  The application's main() function must be called with C linkage,
slouken@3407
    97
 *  and should be declared like this:
slouken@3407
    98
 *  \code
slouken@3407
    99
 *  #ifdef __cplusplus
slouken@3407
   100
 *  extern "C"
slouken@3407
   101
 *  #endif
slouken@3407
   102
 *  int main(int argc, char *argv[])
slouken@3407
   103
 *  {
slouken@3407
   104
 *  }
slouken@3407
   105
 *  \endcode
slouken@0
   106
 */
slouken@3407
   107
slouken@7335
   108
#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
slouken@7191
   109
#define main    SDL_main
slouken@5320
   110
#endif
slouken@0
   111
slouken@0
   112
#include "begin_code.h"
slouken@0
   113
#ifdef __cplusplus
slouken@0
   114
extern "C" {
slouken@0
   115
#endif
slouken@0
   116
philipp@7653
   117
/**
slouken@12662
   118
 *  The prototype for the application's main() function
slouken@12662
   119
 */
slouken@12662
   120
typedef int (*SDL_main_func)(int argc, char *argv[]);
slouken@12663
   121
extern SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);
slouken@12662
   122
slouken@12662
   123
slouken@12662
   124
/**
slouken@7281
   125
 *  This is called by the real SDL main function to let the rest of the
slouken@7281
   126
 *  library know that initialization was done properly.
slouken@7281
   127
 *
slouken@7281
   128
 *  Calling this yourself without knowing what you're doing can cause
slouken@7281
   129
 *  crashes and hard to diagnose problems with your application.
slouken@7281
   130
 */
icculus@8028
   131
extern DECLSPEC void SDLCALL SDL_SetMainReady(void);
slouken@7281
   132
slouken@5320
   133
#ifdef __WIN32__
slouken@5320
   134
slouken@3407
   135
/**
slouken@3407
   136
 *  This can be called to set the application class at startup
slouken@3407
   137
 */
slouken@12659
   138
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style, void *hInst);
slouken@1466
   139
extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
slouken@1895
   140
slouken@5320
   141
#endif /* __WIN32__ */
slouken@5320
   142
slouken@5320
   143
dludwig@8531
   144
#ifdef __WINRT__
dludwig@8531
   145
dludwig@8531
   146
/**
dludwig@8531
   147
 *  \brief Initializes and launches an SDL/WinRT application.
dludwig@8531
   148
 *
dludwig@8531
   149
 *  \param mainFunction The SDL app's C-style main().
dludwig@9297
   150
 *  \param reserved Reserved for future use; should be NULL
philipp@9568
   151
 *  \return 0 on success, -1 on failure.  On failure, use SDL_GetError to retrieve more
dludwig@8531
   152
 *      information on the failure.
dludwig@8531
   153
 */
slouken@12659
   154
extern DECLSPEC int SDLCALL SDL_WinRTRunApp(SDL_main_func mainFunction, void * reserved);
dludwig@8531
   155
dludwig@8531
   156
#endif /* __WINRT__ */
dludwig@8531
   157
slouken@12659
   158
#if defined(__IPHONEOS__)
slouken@12659
   159
slouken@12659
   160
/**
slouken@12659
   161
 *  \brief Initializes and launches an SDL application.
slouken@12659
   162
 *
slouken@12659
   163
 *  \param argc The argc parameter from the application's main() function
slouken@12659
   164
 *  \param argv The argv parameter from the application's main() function
slouken@12659
   165
 *  \param mainFunction The SDL app's C-style main().
slouken@12659
   166
 *  \return the return value from mainFunction
slouken@12659
   167
 */
slouken@12659
   168
extern DECLSPEC int SDLCALL SDL_UIKitRunApp(int argc, char *argv[], SDL_main_func mainFunction);
slouken@12659
   169
slouken@12659
   170
#endif /* __IPHONEOS__ */
slouken@12659
   171
dludwig@8531
   172
slouken@0
   173
#ifdef __cplusplus
slouken@0
   174
}
slouken@0
   175
#endif
slouken@0
   176
#include "close_code.h"
slouken@0
   177
slouken@10638
   178
#endif /* SDL_main_h_ */
slouken@1895
   179
slouken@1895
   180
/* vi: set ts=4 sw=4 expandtab: */