Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "Win32 (MinGW-w64 cross)",
"compilerPath": "i686-w64-mingw32-gcc",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/libcppunitx"
],
"defines": [
"HAVE_CONFIG_H"
],
"cStandard": "c11",
"cppStandard": "c++11",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "Win32 (MSVC)",
"intelliSenseMode": "msvc-x64",
Expand Down
16 changes: 14 additions & 2 deletions libcppunitx/module_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include <config.h>
#endif

#if _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif

#include "module_loader.h"

#if HAVE_DLFCN_H
Expand Down Expand Up @@ -108,24 +113,31 @@ void module::open(const char *const name)
close();
#if HAVE_DLFCN_H
_native_handle = dlopen(name, RTLD_LAZY);
#elif _WIN32
_native_handle = LoadLibraryA(name);
#endif
}

void module::close()
{
#if HAVE_DLFCN_H
native_handle_type handle = nullptr;
std::swap(_native_handle, handle);
if (handle != nullptr) {
#if HAVE_DLFCN_H
dlclose(handle);
}
#elif _WIN32
FreeLibrary(static_cast<HMODULE>(handle));
#endif
}
}

void *module::sym(const char *symbol)
{
#if HAVE_DLFCN_H
return dlsym(_native_handle, symbol);
#elif _WIN32
return reinterpret_cast<void *>(
GetProcAddress(static_cast<HMODULE>(_native_handle), symbol));
#else
return nullptr;
#endif
Expand Down