diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-06-21 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-12-17 14:59:19 +0500 |
| commit | 5b39dc76f1bc82f941d5c800ab9f34407a06b53a (patch) | |
| tree | fe5e17420300b715021a76328444088d32047963 /CPP/Windows/DLL.cpp | |
| parent | 93be7d4abfd4233228f58ee1fbbcd76d91be66a4 (diff) | |
| download | 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.gz 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.bz2 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.zip | |
23.0123.01
Diffstat (limited to 'CPP/Windows/DLL.cpp')
| -rw-r--r-- | CPP/Windows/DLL.cpp | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/CPP/Windows/DLL.cpp b/CPP/Windows/DLL.cpp index cf5d01a..b2499ec 100644 --- a/CPP/Windows/DLL.cpp +++ b/CPP/Windows/DLL.cpp | |||
| @@ -17,11 +17,11 @@ namespace NDLL { | |||
| 17 | 17 | ||
| 18 | bool CLibrary::Free() throw() | 18 | bool CLibrary::Free() throw() |
| 19 | { | 19 | { |
| 20 | if (_module == 0) | 20 | if (_module == NULL) |
| 21 | return true; | 21 | return true; |
| 22 | if (!::FreeLibrary(_module)) | 22 | if (!::FreeLibrary(_module)) |
| 23 | return false; | 23 | return false; |
| 24 | _module = 0; | 24 | _module = NULL; |
| 25 | return true; | 25 | return true; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| @@ -90,7 +90,7 @@ bool MyGetModuleFileName(FString &path) | |||
| 90 | return false; | 90 | return false; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | #ifndef _SFX | 93 | #ifndef Z7_SFX |
| 94 | 94 | ||
| 95 | FString GetModuleDirPrefix() | 95 | FString GetModuleDirPrefix() |
| 96 | { | 96 | { |
| @@ -110,38 +110,35 @@ FString GetModuleDirPrefix() | |||
| 110 | 110 | ||
| 111 | }} | 111 | }} |
| 112 | 112 | ||
| 113 | #else | 113 | #else // _WIN32 |
| 114 | 114 | ||
| 115 | #include <dlfcn.h> | 115 | #include <dlfcn.h> |
| 116 | #include <stdlib.h> | 116 | #include <stdlib.h> |
| 117 | #include "../Common/Common.h" | ||
| 118 | |||
| 119 | // FARPROC | ||
| 120 | void *GetProcAddress(HMODULE module, LPCSTR procName) | ||
| 121 | { | ||
| 122 | void *ptr = NULL; | ||
| 123 | if (module) | ||
| 124 | ptr = dlsym(module, procName); | ||
| 125 | return ptr; | ||
| 126 | } | ||
| 117 | 127 | ||
| 118 | namespace NWindows { | 128 | namespace NWindows { |
| 119 | namespace NDLL { | 129 | namespace NDLL { |
| 120 | 130 | ||
| 121 | bool CLibrary::Free() throw() | 131 | bool CLibrary::Free() throw() |
| 122 | { | 132 | { |
| 123 | if (_module == NULL) | 133 | if (!_module) |
| 124 | return true; | 134 | return true; |
| 125 | int ret = dlclose(_module); | 135 | const int ret = dlclose(_module); |
| 126 | if (ret != 0) | 136 | if (ret != 0) |
| 127 | return false; | 137 | return false; |
| 128 | _module = NULL; | 138 | _module = NULL; |
| 129 | return true; | 139 | return true; |
| 130 | } | 140 | } |
| 131 | 141 | ||
| 132 | static | ||
| 133 | // FARPROC | ||
| 134 | void * | ||
| 135 | local_GetProcAddress(HMODULE module, LPCSTR procName) | ||
| 136 | { | ||
| 137 | void *ptr = NULL; | ||
| 138 | if (module) | ||
| 139 | { | ||
| 140 | ptr = dlsym(module, procName); | ||
| 141 | } | ||
| 142 | return ptr; | ||
| 143 | } | ||
| 144 | |||
| 145 | bool CLibrary::Load(CFSTR path) throw() | 142 | bool CLibrary::Load(CFSTR path) throw() |
| 146 | { | 143 | { |
| 147 | if (!Free()) | 144 | if (!Free()) |
| @@ -163,21 +160,11 @@ bool CLibrary::Load(CFSTR path) throw() | |||
| 163 | #endif | 160 | #endif |
| 164 | #endif | 161 | #endif |
| 165 | 162 | ||
| 166 | void *handler = dlopen(path, options); | 163 | _module = dlopen(path, options); |
| 167 | |||
| 168 | if (handler) | ||
| 169 | { | ||
| 170 | // here we can transfer some settings to DLL | ||
| 171 | } | ||
| 172 | else | ||
| 173 | { | ||
| 174 | } | ||
| 175 | |||
| 176 | _module = handler; | ||
| 177 | |||
| 178 | return (_module != NULL); | 164 | return (_module != NULL); |
| 179 | } | 165 | } |
| 180 | 166 | ||
| 167 | /* | ||
| 181 | // FARPROC | 168 | // FARPROC |
| 182 | void * CLibrary::GetProc(LPCSTR procName) const | 169 | void * CLibrary::GetProc(LPCSTR procName) const |
| 183 | { | 170 | { |
| @@ -185,6 +172,7 @@ void * CLibrary::GetProc(LPCSTR procName) const | |||
| 185 | return local_GetProcAddress(_module, procName); | 172 | return local_GetProcAddress(_module, procName); |
| 186 | // return NULL; | 173 | // return NULL; |
| 187 | } | 174 | } |
| 175 | */ | ||
| 188 | 176 | ||
| 189 | }} | 177 | }} |
| 190 | 178 | ||
