diff --git a/openrct2.sln b/openrct2.sln index c98f53ac32..c161447964 100644 --- a/openrct2.sln +++ b/openrct2.sln @@ -16,6 +16,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2202A816-377 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{480B577D-4E4A-4757-9A42-28A9AD33E6B0}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-win", "src\openrct2-win\openrct2-win.vcxproj", "{7A9A57D5-7006-4208-A290-5491BA3C8808}" + ProjectSection(ProjectDependencies) = postProject + {D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -65,6 +70,22 @@ Global {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|Win32.Build.0 = ReleaseTests|Win32 {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|x64.ActiveCfg = ReleaseTests|x64 {62B020FA-E4FB-4C6E-B32A-DC999470F155}.ReleaseTests|x64.Build.0 = ReleaseTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.ActiveCfg = Debug|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.Build.0 = Debug|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|x64.ActiveCfg = Debug|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|x64.Build.0 = Debug|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|Win32.ActiveCfg = DebugTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|Win32.Build.0 = DebugTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|x64.ActiveCfg = DebugTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.DebugTests|x64.Build.0 = DebugTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|Win32.ActiveCfg = Release|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|Win32.Build.0 = Release|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.ActiveCfg = Release|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.Release|x64.Build.0 = Release|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|Win32.ActiveCfg = ReleaseTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|Win32.Build.0 = ReleaseTests|Win32 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|x64.ActiveCfg = ReleaseTests|x64 + {7A9A57D5-7006-4208-A290-5491BA3C8808}.ReleaseTests|x64.Build.0 = ReleaseTests|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -73,5 +94,6 @@ Global {D24D94F6-2A74-480C-B512-629C306CE92F} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB} {57E60BA1-FB76-4316-909E-C1449C142327} = {480B577D-4E4A-4757-9A42-28A9AD33E6B0} {62B020FA-E4FB-4C6E-B32A-DC999470F155} = {480B577D-4E4A-4757-9A42-28A9AD33E6B0} + {7A9A57D5-7006-4208-A290-5491BA3C8808} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB} EndGlobalSection EndGlobal diff --git a/src/openrct2-win/openrct2-win.cpp b/src/openrct2-win/openrct2-win.cpp new file mode 100644 index 0000000000..433607d313 --- /dev/null +++ b/src/openrct2-win/openrct2-win.cpp @@ -0,0 +1,112 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#define WIN32_LEAN_AND_MEAN + +#include +#include +#include +#include + +// Enable visual styles +#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + +static bool GetCommandLineArgs(int * outargc, char * * * outargv); +static void FreeCommandLineArgs(int argc, char * * argv); +static char * ConvertUTF16toUTF8(const wchar_t * src); + +/** + * Windows entry point to OpenRCT2 with a console window using a traditional C main function. + */ +int main(int argc, char * * argv) +{ + if (!GetCommandLineArgs(&argc, &argv)) + { + puts("Unable to fetch command line arguments."); + return -1; + } + + int exitCode = 0; // RunOpenRCT2 + + FreeCommandLineArgs(argc, argv); + return exitCode; +} + +/** + * Windows entry point to OpenRCT2 without a console window. + */ +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + int argc; + char * * argv; + if (!GetCommandLineArgs(&argc, &argv)) + { + puts("Unable to fetch command line arguments."); + return -1; + } + + int exitCode = 0; // RunOpenRCT2 + + FreeCommandLineArgs(argc, argv); + return exitCode; +} + +static bool GetCommandLineArgs(int * outargc, char * * * outargv) +{ + // Get UTF-16 command line arguments + int argc; + LPWSTR cmdLine = GetCommandLineW(); + LPWSTR * argvW = CommandLineToArgvW(cmdLine, &argc); + + // Allocate UTF-8 strings + char * * argv = (char * *)malloc(argc * sizeof(char *)); + if (argv == nullptr) + { + return false; + } + + // Convert to UTF-8 + for (int i = 0; i < argc; i++) + { + argv[i] = ConvertUTF16toUTF8(argvW[i]); + } + + // Free UTF-16 strings + LocalFree(argvW); + + *outargc = argc; + *outargv = argv; + return true; +} + +static void FreeCommandLineArgs(int argc, char * * argv) +{ + // Free argv + for (int i = 0; i < argc; i++) + { + free(argv[i]); + } + free(argv); +} + +static char * ConvertUTF16toUTF8(const wchar_t * src) +{ + int srcLen = lstrlenW(src); + int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr); + char * result = (char *)calloc(1, sizeReq + 1); + WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr); + return result; +} diff --git a/src/openrct2-win/openrct2-win.vcxproj b/src/openrct2-win/openrct2-win.vcxproj new file mode 100644 index 0000000000..33c89c907c --- /dev/null +++ b/src/openrct2-win/openrct2-win.vcxproj @@ -0,0 +1,75 @@ + + + + ..\..\ + + + + Debug + Win32 + + + Debug + x64 + + + DebugTests + Win32 + + + DebugTests + x64 + + + Release + Win32 + + + Release + x64 + + + ReleaseTests + Win32 + + + ReleaseTests + x64 + + + + {7A9A57D5-7006-4208-A290-5491BA3C8808} + openrct2-win + openrct2-win + + + Application + + + + + __NOENTRYPOINT__;%(PreprocessorDefinitions) + + + + + $(IntDir)\%(RelativeDir) + $(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions) + + + Console + Windows + + + MachineX86 + MachineX64 + + + + + + + + + + \ No newline at end of file