From 052f286eb5dddecf57de3968795838d98640c087 Mon Sep 17 00:00:00 2001 From: George Wu Date: Sat, 25 Apr 2020 20:45:08 +0200 Subject: [PATCH] Fix dll loading --- src/apps/hcaenc/hcaenc.cpp | 4 +-- src/lib/cgss_env.h | 46 ++++++++++++++++------------------ src/lib/cgss_env_ns.h | 8 ++++++ src/lib/cgss_env_platform.h | 17 +++++++++++++ src/lib/takamori/Utilities.cpp | 12 ++++----- src/lib/takamori/Utilities.h | 3 +-- 6 files changed, 55 insertions(+), 35 deletions(-) create mode 100644 src/lib/cgss_env_ns.h create mode 100644 src/lib/cgss_env_platform.h diff --git a/src/apps/hcaenc/hcaenc.cpp b/src/apps/hcaenc/hcaenc.cpp index 77afd9f..05c221d 100644 --- a/src/apps/hcaenc/hcaenc.cpp +++ b/src/apps/hcaenc/hcaenc.cpp @@ -1,7 +1,6 @@ #include -#include -#include "../../lib/cgss_api.h" +#include "../../lib/cgss_env_platform.h" #define VGAUDIO_APP_LINK "https://github.com/hozuki/vgaudio-cpp" #define HCAENC_DLL_FILE_NAME "hcaenc_lite.dll" @@ -13,6 +12,7 @@ #ifdef __CGSS_ARCH_X86__ #include +#include #include "../../lib/takamori/Utilities.h" diff --git a/src/lib/cgss_env.h b/src/lib/cgss_env.h index c1135d1..5bd941c 100644 --- a/src/lib/cgss_env.h +++ b/src/lib/cgss_env.h @@ -1,27 +1,6 @@ #pragma once -#if (defined(_WIN64) || defined(__LP64__) || defined(__LLP64__)) -#define __CGSS_ARCH_X64__ -#else -#define __CGSS_ARCH_X86__ -#endif - -#if (defined(_WIN32) || defined(__CYGWIN__)) -#define __CGSS_OS_WINDOWS__ -#ifndef _MBCS -#define _MBCS -#endif -#define _CRT_SECURE_NO_WARNINGS -#define WIN32_LEAN_AND_MEAN - -// "#ifndef" for warnings in Cygwin/MinGW -#ifndef NOMINMAX -#define NOMINMAX -#endif - -#else -#define __CGSS_OS_UNIX__ -#endif +#include "cgss_env_platform.h" #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__) #ifdef __CGSS_BUILDING_DLL__ @@ -75,9 +54,11 @@ #endif #ifdef __cplusplus + #include #include #include + #else #include @@ -120,10 +101,25 @@ typedef const char *LPCSTR; #define _REF_ #endif -#ifdef __cplusplus -#define CGSS_NS_BEGIN namespace cgss { -#define CGSS_NS_END } +#include "cgss_env_ns.h" + +#ifdef __CGSS_OS_WINDOWS__ + +#ifndef _MBCS +#define _MBCS +#endif + +#define _CRT_SECURE_NO_WARNINGS +#define WIN32_LEAN_AND_MEAN +// "#ifndef" for warnings in Cygwin/MinGW +#ifndef NOMINMAX +#define NOMINMAX +#endif + +#endif + +#ifdef __cplusplus #define PURE_STATIC(className) \ public: \ className() = delete; \ diff --git a/src/lib/cgss_env_ns.h b/src/lib/cgss_env_ns.h new file mode 100644 index 0000000..70862b0 --- /dev/null +++ b/src/lib/cgss_env_ns.h @@ -0,0 +1,8 @@ +#pragma once + +#ifdef __cplusplus + +#define CGSS_NS_BEGIN namespace cgss { +#define CGSS_NS_END } + +#endif diff --git a/src/lib/cgss_env_platform.h b/src/lib/cgss_env_platform.h new file mode 100644 index 0000000..8739418 --- /dev/null +++ b/src/lib/cgss_env_platform.h @@ -0,0 +1,17 @@ +#pragma once + +#if (defined(_WIN64) || defined(__LP64__) || defined(__LLP64__)) +#define __CGSS_ARCH_X64__ +#else +#define __CGSS_ARCH_X86__ +#endif + +#if (defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__)) + +#define __CGSS_OS_WINDOWS__ + +#else + +#define __CGSS_OS_UNIX__ + +#endif diff --git a/src/lib/takamori/Utilities.cpp b/src/lib/takamori/Utilities.cpp index a86b09b..b163ab3 100644 --- a/src/lib/takamori/Utilities.cpp +++ b/src/lib/takamori/Utilities.cpp @@ -1,14 +1,14 @@ -#include "../cgss_env.h" +#include "Utilities.h" -#ifdef __CGSS_OS_WINDOWS__ +#if defined(__CGSS_OS_WINDOWS__) #include -#elif __CGSS_OS_UNIX__ +#elif defined(__CGSS_OS_UNIX__) + #include -#endif -#include "Utilities.h" +#endif CGSS_NS_BEGIN @@ -20,7 +20,7 @@ CGSS_NS_BEGIN #endif } - void *Utilities::GetFunctionAddress(cgss::Utilities::CHLIB hModule, const char *lpstrFuncName) { + void *Utilities::GetFunctionAddress(cgss::Utilities::HLIB hModule, const char *lpstrFuncName) { #if defined(__CGSS_OS_WINDOWS__) return (void *)GetProcAddress((HMODULE)hModule, lpstrFuncName); #elif defined(__CGSS_OS_UNIX__) diff --git a/src/lib/takamori/Utilities.h b/src/lib/takamori/Utilities.h index d002ffa..052c44c 100644 --- a/src/lib/takamori/Utilities.h +++ b/src/lib/takamori/Utilities.h @@ -9,11 +9,10 @@ CGSS_NS_BEGIN public: typedef void *HLIB; - typedef const void *CHLIB; static HLIB LoadDynamicLibrary(const char *lpstrModuleName); - static void *GetFunctionAddress(CHLIB hModule, const char *lpstrFuncName); + static void *GetFunctionAddress(HLIB hModule, const char *lpstrFuncName); static bool_t FreeDynamicLibrary(HLIB hModule);