diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:21:41 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:21:41 +0200 |
commit | d6301fca6b78db52d0d98f8e0799aba175ad2e59 (patch) | |
tree | 0380aac034e0d70ee058db07900d80ff20cfc81e /zen/dll.h | |
parent | 5.7 (diff) | |
download | FreeFileSync-d6301fca6b78db52d0d98f8e0799aba175ad2e59.tar.gz FreeFileSync-d6301fca6b78db52d0d98f8e0799aba175ad2e59.tar.bz2 FreeFileSync-d6301fca6b78db52d0d98f8e0799aba175ad2e59.zip |
5.8
Diffstat (limited to 'zen/dll.h')
-rw-r--r-- | zen/dll.h | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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; }; |