mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-22 10:21:57 -05:00
Create DLL for openrct2 with win as a wrapper
This commit is contained in:
parent
73b21b5880
commit
7d6ea1f5cd
6 changed files with 164 additions and 88 deletions
15
openrct2.sln
15
openrct2.sln
|
@ -17,6 +17,12 @@ 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
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261} = {7B8DB129-79EF-417E-B372-8A18E009D261}
|
||||
{D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-dll", "src\openrct2-dll\openrct2-dll.vcxproj", "{7B8DB129-79EF-417E-B372-8A18E009D261}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F}
|
||||
EndProjectSection
|
||||
|
@ -58,6 +64,14 @@ Global
|
|||
{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
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|x64.Build.0 = Debug|x64
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|Win32.Build.0 = Release|Win32
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|x64.ActiveCfg = Release|x64
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -67,5 +81,6 @@ Global
|
|||
{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}
|
||||
{7B8DB129-79EF-417E-B372-8A18E009D261} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
80
src/openrct2-dll/openrct2-dll.cpp
Normal file
80
src/openrct2-dll/openrct2-dll.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
|
||||
#define DLLEXPORT extern "C" __declspec(dllexport)
|
||||
|
||||
static char * * GetCommandLineArgs(int argc, wchar_t * * argvW);
|
||||
static void FreeCommandLineArgs(int argc, char * * argv);
|
||||
static char * ConvertUTF16toUTF8(const wchar_t * src);
|
||||
|
||||
DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t * * argvW)
|
||||
{
|
||||
char * * argv = GetCommandLineArgs(argc, argvW);
|
||||
if (argv == nullptr)
|
||||
{
|
||||
puts("Unable to fetch command line arguments.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int exitCode = RunOpenRCT2(argc, argv);
|
||||
FreeCommandLineArgs(argc, argv);
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
static char * * GetCommandLineArgs(int argc, wchar_t * * argvW)
|
||||
{
|
||||
// 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]);
|
||||
}
|
||||
|
||||
return argv;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
62
src/openrct2-dll/openrct2-dll.vcxproj
Normal file
62
src/openrct2-dll/openrct2-dll.vcxproj
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<SolutionDir Condition="'$(SolutionDir)'==''">..\..\</SolutionDir>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{7B8DB129-79EF-417E-B372-8A18E009D261}</ProjectGuid>
|
||||
<RootNamespace>openrct2-dll</RootNamespace>
|
||||
<ProjectName>openrct2-dll</ProjectName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
</PropertyGroup>
|
||||
<Import Project="..\..\openrct2.common.props" />
|
||||
<PropertyGroup>
|
||||
<TargetName>openrct2</TargetName>
|
||||
<LibraryPath>$(SolutionDir)bin;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)'=='DebugTests' OR '$(Configuration)'=='ReleaseTests'">__NOENTRYPOINT__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<ObjectFileName>$(IntDir)\%(RelativeDir)</ObjectFileName>
|
||||
<AdditionalOptions>$(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>openrct2-lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<Lib>
|
||||
<TargetMachine Condition="'$(Platform)'=='Win32'">MachineX86</TargetMachine>
|
||||
<TargetMachine Condition="'$(Platform)'=='x64'">MachineX64</TargetMachine>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\..\resources\OpenRCT2.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="openrct2-dll.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
|
@ -16,98 +16,18 @@
|
|||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
|
||||
// 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);
|
||||
#define DLLIMPORT extern "C"
|
||||
DLLIMPORT int LaunchOpenRCT2(int argc, wchar_t * * argv);
|
||||
|
||||
/**
|
||||
* Windows entry point to OpenRCT2 with a console window using a traditional C main function.
|
||||
*/
|
||||
int main(int argc, char * * argv)
|
||||
int wmain(int argc, wchar_t * * argvW, wchar_t * envp)
|
||||
{
|
||||
if (!GetCommandLineArgs(&argc, &argv))
|
||||
{
|
||||
puts("Unable to fetch command line arguments.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int exitCode = RunOpenRCT2(argc, argv);
|
||||
|
||||
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 = RunOpenRCT2(argc, argv);
|
||||
|
||||
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;
|
||||
return LaunchOpenRCT2(argc, argvW);
|
||||
}
|
||||
|
|
|
@ -45,9 +45,8 @@
|
|||
<AdditionalOptions>$(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>openrct2-lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<SubSystem Condition="'$(Configuration)'!='Release'">Console</SubSystem>
|
||||
<SubSystem Condition="'$(Configuration)'=='Release'">Windows</SubSystem>
|
||||
<AdditionalDependencies>openrct2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
<Lib>
|
||||
<TargetMachine Condition="'$(Platform)'=='Win32'">MachineX86</TargetMachine>
|
||||
|
|
|
@ -88,7 +88,7 @@ extern "C"
|
|||
int cmdline_run(const char * * argv, int argc);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
int RunOpenRCT2(int argc, char * *);
|
||||
int RunOpenRCT2(int argc, char * * argv);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Reference in a new issue