- DLxxx functions moved to libnetxms
[public/netxms.git] / src / libnetxms / dload.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Utility Library
4 ** Copyright (C) 2003, 2004 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** $module: dload.cpp
21 **
22 **/
23
24 #include "libnetxms.h"
25
26
27 //
28 // Load DLL/shared library
29 //
30
31 HMODULE LIBNETXMS_EXPORTABLE DLOpen(char *szLibName, char *pszErrorText)
32 {
33 HMODULE hModule;
34
35 #ifdef _WIN32
36 hModule = LoadLibrary(szLibName);
37 if (hModule == NULL)
38 GetSystemErrorText(GetLastError(), pszErrorText, 255);
39 #else /* _WIN32 */
40 hModule = dlopen(szLibName, RTLD_NOW | RTLD_GLOBAL);
41 if (hModule == NULL)
42 strncpy(pszErrorText, dlerror(), 255);
43 #endif
44 return hModule;
45 }
46
47
48 //
49 // Unload DLL/shared library
50 //
51
52 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule)
53 {
54 #ifdef _WIN32
55 FreeLibrary(hModule);
56 #else /* _WIN32 */
57 dlclose(hModule);
58 #endif
59 }
60
61
62 //
63 // Get symbol address from library
64 //
65
66 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, char *szSymbol, char *pszErrorText)
67 {
68 void *pAddr;
69
70 #ifdef _WIN32
71 pAddr = GetProcAddress(hModule, szSymbol);
72 if (pAddr == NULL)
73 GetSystemErrorText(GetLastError(), pszErrorText, 255);
74 #else /* _WIN32 */
75 pAddr = dlsym(hModule, szSymbol);
76 if (pAddr == NULL)
77 strncpy(pszErrorText, dlerror(), 255);
78 #endif
79 return pAddr;
80 }