File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 11
22#include " Module.h"
33
4- #include < iostream>
5-
64namespace HttpServer
75{
86 Module::Module (): lib_handle(nullptr )
@@ -33,7 +31,35 @@ namespace HttpServer
3331 }
3432
3533 #ifdef WIN32
36- lib_handle = ::LoadLibrary (libPath.c_str () );
34+ const size_t pos_slash = libPath.rfind (' \\ ' );
35+ const size_t pos_slash_back = libPath.rfind (' /' );
36+
37+ size_t pos = std::string::npos;
38+
39+ if (pos_slash != std::string::npos && pos_slash > pos_slash_back)
40+ {
41+ pos = pos_slash;
42+ }
43+ else if (pos_slash_back != std::string::npos)
44+ {
45+ pos = pos_slash_back;
46+ }
47+
48+ DLL_DIRECTORY_COOKIE cookie = nullptr ;
49+
50+ if (std::string::npos != pos)
51+ {
52+ std::wstring directory (libPath.cbegin (), libPath.cbegin () + pos + 1 );
53+
54+ cookie = ::AddDllDirectory (directory.data () );
55+ }
56+
57+ lib_handle = ::LoadLibraryEx (libPath.c_str (), 0 , LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
58+
59+ if (cookie)
60+ {
61+ ::RemoveDllDirectory (cookie);
62+ }
3763 #elif POSIX
3864 lib_handle = ::dlopen (libPath.c_str (), RTLD_NOW | RTLD_LOCAL);
3965 #else
You can’t perform that action at this time.
0 commit comments