From daa49af2476b0733dd4f67897958e7d621d6cb36 Mon Sep 17 00:00:00 2001 From: Jordon Brooks Date: Fri, 31 May 2024 23:43:22 +0100 Subject: [PATCH] Working in UE4 --- .gitignore | 1 + HarmonyLinkLib/CMakeLists.txt | 1 - HarmonyLinkLib/include/HarmonyLinkLib.h | 16 ++++--- HarmonyLinkLib/src/HarmonyLinkLib.cpp | 13 ++++-- HarmonyLinkLib/src/dllmain.cpp | 61 ------------------------- HarmonyLinkTest/src/main.cpp | 10 +++- 6 files changed, 29 insertions(+), 73 deletions(-) delete mode 100644 HarmonyLinkLib/src/dllmain.cpp diff --git a/.gitignore b/.gitignore index a7fdac2..2e552b2 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ winbuild/ !Compile.sh !Compile.bat +HarmonyLinkLib/.vscode/ diff --git a/HarmonyLinkLib/CMakeLists.txt b/HarmonyLinkLib/CMakeLists.txt index eba9442..e61dfb3 100644 --- a/HarmonyLinkLib/CMakeLists.txt +++ b/HarmonyLinkLib/CMakeLists.txt @@ -69,7 +69,6 @@ set(COMMON_SOURCES "src/Platform/IPlatformUtilities.cpp" "src/HarmonyLinkLib.cpp" "src/Version.cpp" - "src/dllmain.cpp" "src/Platform/WineUtilities.cpp" "src/Utilities.cpp" ) diff --git a/HarmonyLinkLib/include/HarmonyLinkLib.h b/HarmonyLinkLib/include/HarmonyLinkLib.h index d6575a5..0298e2d 100644 --- a/HarmonyLinkLib/include/HarmonyLinkLib.h +++ b/HarmonyLinkLib/include/HarmonyLinkLib.h @@ -44,17 +44,19 @@ class IPlatformUtilities; namespace HarmonyLinkLib { - extern "C" HARMONYLINKLIB_API bool get_is_wine(); + HARMONYLINKLIB_API bool HL_Init(); - extern "C" HARMONYLINKLIB_API bool get_is_linux(); + HARMONYLINKLIB_API bool get_is_wine(); - extern "C" HARMONYLINKLIB_API bool get_is_docked(); + HARMONYLINKLIB_API bool get_is_linux(); - extern "C" HARMONYLINKLIB_API FCPUInfo* get_cpu_info(); + HARMONYLINKLIB_API bool get_is_docked(); - extern "C" HARMONYLINKLIB_API FDevice* get_device_info(); + HARMONYLINKLIB_API FCPUInfo* get_cpu_info(); - extern "C" HARMONYLINKLIB_API FOSVerInfo* get_os_version(); + HARMONYLINKLIB_API FDevice* get_device_info(); + + HARMONYLINKLIB_API FOSVerInfo* get_os_version(); - extern "C" HARMONYLINKLIB_API FBattery* get_battery_status(); + HARMONYLINKLIB_API FBattery* get_battery_status(); } diff --git a/HarmonyLinkLib/src/HarmonyLinkLib.cpp b/HarmonyLinkLib/src/HarmonyLinkLib.cpp index 91ccc2c..f57feac 100644 --- a/HarmonyLinkLib/src/HarmonyLinkLib.cpp +++ b/HarmonyLinkLib/src/HarmonyLinkLib.cpp @@ -16,10 +16,19 @@ #include #include "Platform/IPlatformUtilities.h" +#include "Version.h" namespace HarmonyLinkLib { - std::shared_ptr PlatformUtilities = IPlatformUtilities::GetInstance(); + std::shared_ptr PlatformUtilities = nullptr; + + bool HL_Init() + { + std::wcout << "HarmonyLink V" << version::ToString().c_str() << " Copyright (C) 2023 Jordon Brooks\n"; + PlatformUtilities = IPlatformUtilities::GetInstance(); + + return PlatformUtilities != nullptr; + } bool get_is_wine() { @@ -92,8 +101,6 @@ namespace HarmonyLinkLib FOSVerInfo* get_os_version() { - - if (!PlatformUtilities) { std::wcout << "Failed to get platform utilities!\n"; diff --git a/HarmonyLinkLib/src/dllmain.cpp b/HarmonyLinkLib/src/dllmain.cpp deleted file mode 100644 index 5e6df48..0000000 --- a/HarmonyLinkLib/src/dllmain.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2024 Jordon Brooks -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "Version.h" - -namespace HarmonyLinkLib -{ - void HarmonyLinkInit() - { - std::wcout << "HarmonyLink V" << version::ToString().c_str() << " Copyright (C) 2023 Jordon Brooks\n"; - } -} - - -#if BUILD_WINDOWS -#include - -// Standard DLL entry point -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - switch (fdwReason) { - case DLL_PROCESS_ATTACH: - // Code to run when the DLL is loaded - HarmonyLinkLib::HarmonyLinkInit(); - break; - case DLL_THREAD_ATTACH: - // Code to run when a thread is created during the DLL's lifetime - case DLL_THREAD_DETACH: - // Code to run when a thread ends normally. - case DLL_PROCESS_DETACH: - // Code to run when the DLL is unloaded - default: - break; - } - return TRUE; // Successful DLL_PROCESS_ATTACH. -} -#endif - -#if BUILD_UNIX -__attribute__((constructor)) -static void onLibraryLoad() { - // Code to run when the library is loaded - HarmonyLinkLib::HarmonyLinkInit(); -} - -__attribute__((destructor)) -static void onLibraryUnload() { - // Code to run when the library is unloaded -} -#endif diff --git a/HarmonyLinkTest/src/main.cpp b/HarmonyLinkTest/src/main.cpp index e9eaf87..d4d2d29 100644 --- a/HarmonyLinkTest/src/main.cpp +++ b/HarmonyLinkTest/src/main.cpp @@ -85,10 +85,18 @@ void checkForQuit() { int main() { - std::cout << "Hello, World!" << '\n'; + std::cout << "Hello, World!\n"; std::thread inputThread(checkForQuit); + if (!HarmonyLinkLib::HL_Init()) + { + std::cout << "Failed to init HarmonyLinkLib\n"; + return 1; + } + + std::cout << "HarmonyLinkLib successfully initialised!\n"; + const bool isWine = HarmonyLinkLib::get_is_wine(); const char* test = isWine ? "is" : "isn't";