SDL_main.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef SDL_main_h_
  19. #define SDL_main_h_
  20. #include "SDL_stdinc.h"
  21. /**
  22. * \file SDL_main.h
  23. *
  24. * Redefine main() on some platforms so that it is called by SDL.
  25. */
  26. #ifndef SDL_MAIN_HANDLED
  27. #if defined(__WIN32__)
  28. /* On Windows SDL provides WinMain(), which parses the command line and passes
  29. the arguments to your main function.
  30. If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
  31. */
  32. #define SDL_MAIN_AVAILABLE
  33. #elif defined(__WINRT__)
  34. /* On WinRT, SDL provides a main function that initializes CoreApplication,
  35. creating an instance of IFrameworkView in the process.
  36. Please note that #include'ing SDL_main.h is not enough to get a main()
  37. function working. In non-XAML apps, the file,
  38. src/main/winrt/SDL_WinRT_main_NonXAML.cpp, or a copy of it, must be compiled
  39. into the app itself. In XAML apps, the function, SDL_WinRTRunApp must be
  40. called, with a pointer to the Direct3D-hosted XAML control passed in.
  41. */
  42. #define SDL_MAIN_NEEDED
  43. #elif defined(__IPHONEOS__)
  44. /* On iOS SDL provides a main function that creates an application delegate
  45. and starts the iOS application run loop.
  46. See src/video/uikit/SDL_uikitappdelegate.m for more details.
  47. */
  48. #define SDL_MAIN_NEEDED
  49. #elif defined(__ANDROID__)
  50. /* On Android SDL provides a Java class in SDLActivity.java that is the
  51. main activity entry point.
  52. See README-android.md for more details on extending that class.
  53. */
  54. #define SDL_MAIN_NEEDED
  55. #elif defined(__NACL__)
  56. /* On NACL we use ppapi_simple to set up the application helper code,
  57. then wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before
  58. starting the user main function.
  59. All user code is run in a separate thread by ppapi_simple, thus
  60. allowing for blocking io to take place via nacl_io
  61. */
  62. #define SDL_MAIN_NEEDED
  63. #endif
  64. #endif /* SDL_MAIN_HANDLED */
  65. #ifdef __cplusplus
  66. #define C_LINKAGE "C"
  67. #else
  68. #define C_LINKAGE
  69. #endif /* __cplusplus */
  70. /**
  71. * \file SDL_main.h
  72. *
  73. * The application's main() function must be called with C linkage,
  74. * and should be declared like this:
  75. * \code
  76. * #ifdef __cplusplus
  77. * extern "C"
  78. * #endif
  79. * int main(int argc, char *argv[])
  80. * {
  81. * }
  82. * \endcode
  83. */
  84. #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
  85. #define main SDL_main
  86. #endif
  87. /**
  88. * The prototype for the application's main() function
  89. */
  90. extern C_LINKAGE DECLSPEC int SDL_main(int argc, char *argv[]);
  91. #include "begin_code.h"
  92. #ifdef __cplusplus
  93. extern "C" {
  94. #endif
  95. /**
  96. * This is called by the real SDL main function to let the rest of the
  97. * library know that initialization was done properly.
  98. *
  99. * Calling this yourself without knowing what you're doing can cause
  100. * crashes and hard to diagnose problems with your application.
  101. */
  102. extern DECLSPEC void SDLCALL SDL_SetMainReady(void);
  103. #ifdef __WIN32__
  104. /**
  105. * This can be called to set the application class at startup
  106. */
  107. extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
  108. void *hInst);
  109. extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
  110. #endif /* __WIN32__ */
  111. #ifdef __WINRT__
  112. /**
  113. * \brief Initializes and launches an SDL/WinRT application.
  114. *
  115. * \param mainFunction The SDL app's C-style main().
  116. * \param reserved Reserved for future use; should be NULL
  117. * \return 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more
  118. * information on the failure.
  119. */
  120. extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * reserved);
  121. #endif /* __WINRT__ */
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #include "close_code.h"
  126. #endif /* SDL_main_h_ */
  127. /* vi: set ts=4 sw=4 expandtab: */