42 #if defined(NCBI_OS_MSWIN)
44 #elif defined(NCBI_OS_UNIX)
51 # ifdef NCBI_OS_DARWIN
52 # include <mach-o/dyld.h>
55 # error "Class CDll defined only for MS Windows and UNIX platforms"
58 #if defined(NCBI_OS_MSWIN)
59 # pragma warning (disable : 4191)
63 #define NCBI_USE_ERRCODE_X Corelib_Dll
71 #if defined(NCBI_OS_MSWIN)
73 #elif defined(NCBI_OS_UNIX)
79 #define F_ISSET(mask) ((m_Flags & (mask)) == (mask))
81 #define F_CLEAN_REDUNDANT(group) \
82 if (F_ISSET(group)) m_Flags &= ~unsigned((group) & ~unsigned(fDefault))
137 string x_name = name;
138 #if defined(NCBI_OS_MSWIN)
143 name.find_first_of(
":/\\") ==
NPOS &&
166 #if defined(NCBI_OS_MSWIN)
167 UINT errMode = SetErrorMode(SEM_FAILCRITICALERRORS);
169 SetErrorMode(errMode);
170 #elif defined(NCBI_OS_UNIX)
194 #if defined(NCBI_OS_MSWIN)
196 #elif defined(NCBI_OS_UNIX)
200 bool unloaded =
false;
218 _TRACE(
"Getting entry point: "<<name);
222 #if defined(NCBI_OS_MSWIN)
224 #elif defined(NCBI_OS_UNIX) && defined(HAVE_DLFCN_H)
227 #elif defined(NCBI_OS_DARWIN)
229 NSSymbol nssymbol = NSLookupSymbolInModule(module, name.c_str());
231 ptr = NSAddressOfSymbol(nssymbol);
246 #if defined(NCBI_OS_MSWIN)
248 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
249 FORMAT_MESSAGE_FROM_SYSTEM |
250 FORMAT_MESSAGE_IGNORE_INSERTS,
251 NULL, GetLastError(),
252 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
254 string errmsg = ptr ?
_T_CSTRING(ptr) :
"unknown reason";
256 #elif defined(NCBI_OS_UNIX)
258 const char* errmsg = dlerror();
260 errmsg =
"unknown reason";
263 const char* errmsg =
"No DLL support on this platform.";
273 : m_AutoUnloadDll(unload)
280 : m_AutoUnloadDll(unload)
291 const string& driver_name)
305 string entry_point_name;
307 const string& dll_name = dll->
GetName();
309 if ( !dll_name.empty() ) {
312 NStr::Replace(*it,
"${basename}", base_name, entry_point_name);
313 if (!driver_name.empty()) {
314 NStr::Replace(*it,
"${driver}", driver_name, entry_point_name);
320 if ( entry_point_name.empty() )
337 if (dll !=
nullptr) {
371 if ( !dir.empty() ) {
372 paths.push_back(dir);
379 #if defined(NCBI_OS_MSWIN)
382 UINT len = GetSystemDirectory(
buf, MAX_PATH+1);
383 if (
len>0 &&
len<=MAX_PATH) {
386 len = GetWindowsDirectory(
buf, MAX_PATH+1);
387 if (
len>0 &&
len<=MAX_PATH) {
396 #elif defined(NCBI_OS_UNIX)
398 const char*
env = getenv(
"LD_LIBRARY_PATH");
409 if (runpath && *runpath) {
410 # if defined(NCBI_OS_MSWIN)
412 # elif defined(NCBI_OS_UNIX)
413 vector<string> tokenized;
415 ITERATE(vector<string>,
i, tokenized) {
416 if (
i->find(
"$ORIGIN") ==
NPOS) {
420 if ( !dir.empty() ) {
427 paths.push_back(runpath);
static string GetAppName(EAppNameType name_type=eBaseName, int argc=0, const char *const *argv=NULL)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
@ eFullName
per GetProgramExecutablePath(eIgnoreLinks)
const string & GetName() const
Get the name of the DLL file.
SDllHandle * m_Handle
DLL handle.
FEntryPoint func
Do not call this func without type cast!
void(* FEntryPoint)(char ****Do_Not_Call_This)
Fake, uncallable function pointer.
EBasename
Whether to transform the DLL basename.
void x_Init(const string &path, const string &name, TFlags flags)
Helper method to initialize object.
bool TryCandidate(const string &file_name, const string &driver_name=kEmptyStr)
Try to load DLL from the specified file and resolve the entry point.
vector< SResolvedEntry > TEntries
Container, keeps list of all resolved entry points.
vector< SNamedEntryPoint > entry_points
list of DLL entry points
CDllResolver(const string &entry_point_name, CDll::EAutoUnload unload=CDll::eAutoUnload)
Constructor.
EAutoUnload
Whether to unload DLL in the destructor.
CDll::EAutoUnload m_AutoUnloadDll
void Unload()
Unload all resolved DLLs.
unsigned int TFlags
Binary OR of "EFlags".
TEntryPoint GetEntryPoint(const string &name)
Helper find method for getting a DLLs entry point.
#define NCBI_PLUGIN_MIN_SUFFIX
#define NCBI_PLUGIN_SUFFIX
void Unload(void)
Unload DLL.
~CDllResolver()
Destructor.
#define NCBI_PLUGIN_PREFIX
vector< string > m_EntryPoinNames
Candidate entry points.
CDll(const string &name, TFlags flags)
Constructor.
void x_ThrowException(const string &what)
Helper method to throw exception with system-specific error message.
TEntries m_ResolvedEntries
void x_AddExtraDllPath(vector< string > &paths, TExtraDllPath which)
Get the DLL search paths related to the given standard path group.
@ fLoadNow
When to load DLL.
@ fAutoUnload
Whether to unload DLL in the destructor.
@ fBaseName
Whether to transform the DLL basename.
@ fLocal
Load as RTLD_LOCAL.
@ fLoadLater
Load DLL later, using method Load()
@ fExactName
Use the name "as is".
@ fGlobal
Specify how to load symbols from DLL.
@ fNoAutoUnload
Unload DLL later, using method Unload()
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
TErrCode GetErrCode(void) const
#define NCBI_REPORT_EXCEPTION_X(err_subcode, title, ex)
Generate a report on the exception with default error code and given subcode.
static string ConcatPath(const string &first, const string &second)
Concatenate two parts of the path for the current OS.
static bool MatchesMask(const string &name, const string &mask, NStr::ECase use_case=NStr::eCase)
Match a "name" against a simple filename "mask".
static void SplitPath(const string &path, string *dir=0, string *base=0, string *ext=0)
Split a path string into its basic components.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition of all error codes used in corelib (xncbi.lib).
Defines MS Windows specifics for our "C++" code.
Common macro to detect used sanitizers and suppress memory leaks if run under LeakSanitizer.
#define NCBI_LSAN_DISABLE_GUARD
const char * NCBI_GetRunpath(void)
Get run path.
#define F_CLEAN_REDUNDANT(group)
static string s_GetProgramPath(void)
Define class Dll and for Portable DLL handling.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
DLL entry point name -> function pair.
DLL resolution descriptor.
Entry point – pointer to either a function or a data.