summaryrefslogtreecommitdiff
path: root/zen/dll.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:21:41 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:21:41 +0200
commitd6301fca6b78db52d0d98f8e0799aba175ad2e59 (patch)
tree0380aac034e0d70ee058db07900d80ff20cfc81e /zen/dll.h
parent5.7 (diff)
downloadFreeFileSync-d6301fca6b78db52d0d98f8e0799aba175ad2e59.tar.gz
FreeFileSync-d6301fca6b78db52d0d98f8e0799aba175ad2e59.tar.bz2
FreeFileSync-d6301fca6b78db52d0d98f8e0799aba175ad2e59.zip
5.8
Diffstat (limited to 'zen/dll.h')
-rw-r--r--zen/dll.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/zen/dll.h b/zen/dll.h
index 837e21a0..6f139ac3 100644
--- a/zen/dll.h
+++ b/zen/dll.h
@@ -1,7 +1,7 @@
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
-// * Copyright (C) ZenJu (zenju AT gmx DOT de) - All Rights Reserved *
+// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// **************************************************************************
#ifndef DLLLOADER_H_INCLUDED
@@ -20,9 +20,13 @@ Manage DLL function and library ownership
- full value semantics
Usage:
- typedef BOOL (WINAPI* IsWow64ProcessFun)(HANDLE hProcess, PBOOL Wow64Process);
- const zen::SysDllFun<IsWow64ProcessFun> isWow64Process(L"kernel32.dll", "IsWow64Process");
- if (isWow64Process) ... use function ptr ...
+ typedef BOOL (WINAPI* IsWow64ProcessFun)(HANDLE hProcess, PBOOL Wow64Process);
+ const zen::SysDllFun<IsWow64ProcessFun> isWow64Process(L"kernel32.dll", "IsWow64Process");
+ if (isWow64Process) ... use function ptr ...
+
+ Usage 2:
+ #define DEF_DLL_FUN(name) DllFun<dll_ns::FunType_##name> name(getDllName(), dll_ns::funName_##name);
+ DEF_DLL_FUN(funname1); DEF_DLL_FUN(funname2); DEF_DLL_FUN(funname3);
*/
template <class Func>
@@ -32,15 +36,13 @@ public:
DllFun() : fun(nullptr) {}
DllFun(const wchar_t* libraryName, const char* functionName) :
- hLibRef(new HMODULE(::LoadLibrary(libraryName)), deleter),
- fun(*hLibRef ? reinterpret_cast<Func>(::GetProcAddress(*hLibRef, functionName)) : nullptr) {}
+ hLibRef(::LoadLibrary(libraryName), ::FreeLibrary),
+ fun(hLibRef ? reinterpret_cast<Func>(::GetProcAddress(static_cast<HMODULE>(hLibRef.get()), functionName)) : nullptr) {}
operator Func() const { return fun; }
private:
- static void deleter(HMODULE* ptr) { if (*ptr) ::FreeLibrary(*ptr); delete ptr; }
-
- std::shared_ptr<const HMODULE> hLibRef;
+ std::shared_ptr<void> hLibRef; //we would prefer decltype(*HMODULE()) if only it would work...
Func fun;
};
bgstack15