PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Main.h * 00003 * Platform independent main function. This header can ONLY be includes once per project! 00004 * 00005 * Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/) 00006 * 00007 * This file is part of PixelLight. 00008 * 00009 * PixelLight is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU Lesser General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * PixelLight is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public License 00020 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00021 \*********************************************************/ 00022 00023 00024 #ifndef __PLCORE_MAIN_H__ 00025 #define __PLCORE_MAIN_H__ 00026 #pragma once 00027 00028 00029 //[-------------------------------------------------------] 00030 //[ Includes ] 00031 //[-------------------------------------------------------] 00032 #include "PLCore/System/System.h" 00033 #include "PLCore/Tools/CommandLine.h" 00034 00035 00036 //[-------------------------------------------------------] 00037 //[ OS definitions ] 00038 //[-------------------------------------------------------] 00039 // Windows platform 00040 #ifdef WIN32 00041 #include "PLCore/PLCoreWindowsIncludes.h" 00042 #endif 00043 00044 // Linux platform 00045 #ifdef LINUX 00046 #include <locale.h> 00047 #include "PLCore/PLCoreLinuxIncludes.h" 00048 #endif 00049 00050 00051 //[-------------------------------------------------------] 00052 //[ PL main function ] 00053 //[-------------------------------------------------------] 00054 /** 00055 * @brief 00056 * Program entry point 00057 * 00058 * @param[in] sExecutableFilename 00059 * Absolute executable filename 00060 * @param[in] lstArguments 00061 * List of program arguments 00062 * 00063 * @return 00064 * Exit code of the application (usually 0 means no error) 00065 */ 00066 int PLMain(const PLCore::String &sExecutableFilename, const PLCore::Array<PLCore::String> &lstArguments); 00067 00068 00069 //[-------------------------------------------------------] 00070 //[ Program entry point ] 00071 //[-------------------------------------------------------] 00072 // Do only include the program entry point if the current build target is no shared library 00073 // (On e.g. Linux those definitions are set by our build system -> we just use the MS Windows 00074 // names so that we don't have to invent a new definition for this purpose) 00075 #if !defined(_WINDLL) && !defined(_USRDLL) 00076 // Windows implementation 00077 #ifdef WIN32 00078 #ifdef _CONSOLE 00079 #ifdef UNICODE 00080 int wmain(int argc, wchar_t **argv) 00081 #else 00082 int main(int argc, char **argv) 00083 #endif 00084 { 00085 PLCore::Array<PLCore::String> lstArguments; 00086 for (int i=1; i<argc; i++) 00087 lstArguments.Add(argv[i]); 00088 return PLMain(PLCore::System::GetInstance()->GetExecutableFilename(), lstArguments); 00089 } 00090 #else 00091 #ifdef UNICODE 00092 int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR pszCmdLine, int nShow) 00093 #else 00094 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pszCmdLine, int nShow) 00095 #endif 00096 { 00097 return PLMain(PLCore::System::GetInstance()->GetExecutableFilename(), PLCore::CommandLine::StringToArguments(pszCmdLine)); 00098 } 00099 #endif 00100 00101 // Linux implementation 00102 #elif LINUX 00103 int main(int argc, char **argv) 00104 { 00105 PLCore::Array<PLCore::String> lstArguments; 00106 for (int i=1; i<argc; i++) 00107 lstArguments.Add(PLCore::String::FromUTF8(argv[i])); 00108 return PLMain(PLCore::System::GetInstance()->GetExecutableFilename(), lstArguments); 00109 } 00110 #endif 00111 #endif 00112 00113 00114 #endif // __PLCORE_MAIN_H__
|