summaryrefslogtreecommitdiff
path: root/shared/dll_loader.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:08:42 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:08:42 +0200
commitc32707148292d104c66276b43796d6057c8c7a5d (patch)
treebb83513f4aff24153e21a4ec92e34e4c27651b1f /shared/dll_loader.cpp
parent3.9 (diff)
downloadFreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.gz
FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.bz2
FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.zip
3.10
Diffstat (limited to 'shared/dll_loader.cpp')
-rw-r--r--shared/dll_loader.cpp44
1 files changed, 37 insertions, 7 deletions
diff --git a/shared/dll_loader.cpp b/shared/dll_loader.cpp
index 6aa48fd7..61a5a2fb 100644
--- a/shared/dll_loader.cpp
+++ b/shared/dll_loader.cpp
@@ -11,7 +11,7 @@
namespace
{
-class DllHandler //dynamically load "kernel32.dll"
+class DllHandler
{
public:
static DllHandler& getInstance()
@@ -20,12 +20,15 @@ public:
return instance;
}
- HINSTANCE getHandle(const std::wstring& libraryName)
+ HMODULE getHandle(const std::wstring& libraryName)
{
HandleMap::const_iterator foundEntry = handles.find(libraryName);
if (foundEntry == handles.end())
{
- HINSTANCE newHandle = ::LoadLibrary(libraryName.c_str());
+ if (libraryName.empty())
+ return ::GetModuleHandle(NULL); //return handle to calling executable
+
+ HMODULE newHandle = ::LoadLibrary(libraryName.c_str());
if (newHandle != NULL)
handles.insert(std::make_pair(libraryName, newHandle));
@@ -37,6 +40,8 @@ public:
private:
DllHandler() {}
+ DllHandler(const DllHandler&);
+ DllHandler& operator=(const DllHandler&);
~DllHandler()
{
@@ -44,18 +49,43 @@ private:
::FreeLibrary(i->second);
}
- typedef std::map<std::wstring, HINSTANCE> HandleMap;
+ typedef std::map<std::wstring, HMODULE> HandleMap;
HandleMap handles; //only valid handles here!
};
}
-void* util::loadSymbol(const std::wstring& libraryName, const std::string& functionName)
+FARPROC util::loadSymbol(const std::wstring& libraryName, const std::string& functionName)
{
- const HINSTANCE libHandle = DllHandler::getInstance().getHandle(libraryName);
+ const HMODULE libHandle = DllHandler::getInstance().getHandle(libraryName);
if (libHandle != NULL)
- return reinterpret_cast<void*>(::GetProcAddress(libHandle, functionName.c_str()));
+ return ::GetProcAddress(libHandle, functionName.c_str());
else
return NULL;
}
+
+
+std::string util::getResourceStream(const std::wstring& libraryName, size_t resourceId)
+{
+ std::string output;
+ const HMODULE module = DllHandler::getInstance().getHandle(libraryName);
+ if (module)
+ {
+ const HRSRC res = ::FindResource(module, MAKEINTRESOURCE(resourceId), RT_RCDATA);
+ if (res != NULL)
+ {
+ const HGLOBAL resHandle = ::LoadResource(module, res);
+ if (resHandle != NULL)
+ {
+ const char* stream = static_cast<const char*>(::LockResource(resHandle));
+ if (stream)
+ {
+ const DWORD streamSize = ::SizeofResource(module, res);
+ output.assign(stream, streamSize);
+ }
+ }
+ }
+ }
+ return output;
+}
bgstack15