00001 #include "OSDependent/Library.h"
00002 #include "OSDependent/OS.h"
00003
00004 #define DLL_SUFFIX ".dll"
00005
00006 Library::Library() :
00007 _handle(NULL)
00008 {
00009 }
00010
00011 Library::~Library()
00012 {
00013 unload();
00014 }
00015
00016
00017
00018
00019
00020
00021 int
00022 Library::load(const char *libName, int mode)
00023 {
00024
00025 _handle = ::LoadLibrary(libName);
00026
00027 if (_handle == NULL)
00028 return -1;
00029 return 0;
00030 }
00031
00032
00033
00034
00035
00036
00037 int
00038 Library::unload()
00039 {
00040 if (_handle == NULL)
00041 return -1;
00042 if (::FreeLibrary(_handle) == 0) {
00043 _handle = NULL;
00044 return -1;
00045 }
00046
00047 _handle=0;
00048
00049 return 0;
00050 }
00051
00052
00053
00054
00055
00056
00057
00058 void *
00059 Library::getFuncPtr(const char *funcName) const
00060 {
00061 if (_handle == NULL)
00062 return NULL;
00063 return ::GetProcAddress(_handle, funcName);
00064 }
00065
00066
00067
00068
00069
00070 void
00071 Library::getNativeLibName(const char *genericName, char *nativeName)
00072 {
00073 char temp[MAXNAMELEN];
00074 strcpy(temp, genericName);
00075
00076 char *filename = strrchr(temp, OS::DirectorySeparator);
00077 if (filename != NULL) {
00078
00079 *filename = '\0';
00080 filename++;
00081 sprintf(nativeName, "%s%c%s%s", temp, OS::DirectorySeparator,
00082 filename, DLL_SUFFIX);
00083
00084
00085
00086 } else {
00087
00088 sprintf(nativeName, "%s%s", genericName, DLL_SUFFIX);
00089 }
00090 }