2
0

Main.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "ProcessUtils.h"
  25. #ifdef WIN32
  26. #include "MiniDump.h"
  27. #include <windows.h>
  28. #endif
  29. // Define a platform-specific main function, which in turn executes the user-defined function
  30. // MSVC debug mode: use memory leak reporting
  31. #if defined(_MSC_VER) && defined(_DEBUG)
  32. #define DEFINE_MAIN(function) \
  33. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) \
  34. { \
  35. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); \
  36. ParseArguments(GetCommandLineW()); \
  37. function; \
  38. return 0; \
  39. }
  40. // MSVC release mode: write minidump on crash
  41. #elif defined(_MSC_VER) && defined(ENABLE_MINIDUMPS)
  42. #define DEFINE_MAIN(function) \
  43. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) \
  44. { \
  45. ParseArguments(GetCommandLineW()); \
  46. __try \
  47. { \
  48. function; \
  49. } \
  50. __except(WriteMiniDump("Urho3D", GetExceptionInformation())) \
  51. { \
  52. } \
  53. return 0; \
  54. }
  55. // Other Win32 or minidumps disabled: just execute the function
  56. #elif defined(WIN32)
  57. #define DEFINE_MAIN(function) \
  58. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) \
  59. { \
  60. ParseArguments(GetCommandLineW()); \
  61. function; \
  62. return 0; \
  63. }
  64. // Android or iOS: use SDL_main
  65. #elif defined(ANDROID) || defined(IOS)
  66. #define DEFINE_MAIN(function) \
  67. extern "C" int SDL_main(int argc, char** argv); \
  68. int SDL_main(int argc, char** argv) \
  69. { \
  70. ParseArguments(argc, argv); \
  71. function; \
  72. return 0; \
  73. }
  74. // Linux or OS X: use main
  75. #else
  76. #define DEFINE_MAIN(function) \
  77. int main(int argc, char** argv) \
  78. { \
  79. ParseArguments(argc, argv); \
  80. function; \
  81. return 0; \
  82. }
  83. #endif