Skip to content

Commit

Permalink
Fix dll loading
Browse files Browse the repository at this point in the history
  • Loading branch information
hozuki committed Apr 25, 2020
1 parent ac6c9a6 commit 052f286
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/apps/hcaenc/hcaenc.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <cstdio>
#include <Windows.h>

#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"
Expand All @@ -13,6 +12,7 @@
#ifdef __CGSS_ARCH_X86__

#include <iostream>
#include <Windows.h>

#include "../../lib/takamori/Utilities.h"

Expand Down
46 changes: 21 additions & 25 deletions src/lib/cgss_env.h
Original file line number Diff line number Diff line change
@@ -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__
Expand Down Expand Up @@ -75,9 +54,11 @@
#endif

#ifdef __cplusplus

#include <cstdlib>
#include <cstring>
#include <cstdint>

#else

#include <stdlib.h>
Expand Down Expand Up @@ -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; \
Expand Down
8 changes: 8 additions & 0 deletions src/lib/cgss_env_ns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#ifdef __cplusplus

#define CGSS_NS_BEGIN namespace cgss {
#define CGSS_NS_END }

#endif
17 changes: 17 additions & 0 deletions src/lib/cgss_env_platform.h
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions src/lib/takamori/Utilities.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "../cgss_env.h"
#include "Utilities.h"

#ifdef __CGSS_OS_WINDOWS__
#if defined(__CGSS_OS_WINDOWS__)

#include <Windows.h>

#elif __CGSS_OS_UNIX__
#elif defined(__CGSS_OS_UNIX__)

#include <dlfcn.h>
#endif

#include "Utilities.h"
#endif

CGSS_NS_BEGIN

Expand All @@ -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__)
Expand Down
3 changes: 1 addition & 2 deletions src/lib/takamori/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 052f286

Please sign in to comment.