Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary Win32 support #6

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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