X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f4a8c29f7a3ffa7eb60d9b7f055565eb2df368d9..cfad3750c3ecc821ffae8b9b3de852551270846d:/src/common/dynlib.cpp diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 6384eb3a8b..6b8bf78e38 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -13,6 +13,15 @@ #pragma implementation "dynlib.h" #endif +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif //__BORLANDC__ + +#ifndef WX_PRECOMP +#endif //WX_PRECOMP + #include #include #include @@ -22,7 +31,7 @@ // System dependent include // --------------------------------------------------------------------------- -#ifdef __UNIX__ +#if defined(__UNIX__) #include #endif @@ -30,6 +39,10 @@ #include #endif +#ifdef LoadLibrary +#undef LoadLibrary +#endif + // --------------------------------------------------------------------------- // Global variables // --------------------------------------------------------------------------- @@ -42,7 +55,7 @@ wxLibraries wxTheLibraries; wxLibrary::wxLibrary(void *handle) { - typedef wxClassInfo **(*t_get_first)(void); + typedef wxClassInfo *(*t_get_first)(void); t_get_first get_first; m_handle = handle; @@ -58,7 +71,7 @@ wxLibrary::wxLibrary(void *handle) wxLibrary::~wxLibrary() { if (m_handle && m_destroy) { -#ifdef __UNIX__ +#if defined(__UNIX__) dlclose(m_handle); #endif #ifdef __WINDOWS__ @@ -77,37 +90,47 @@ wxObject *wxLibrary::CreateObject(const wxString& name) return info->CreateObject(); } -void wxLibrary::PrepareClasses(wxClassInfo **first) +void wxLibrary::PrepareClasses(wxClassInfo *first) { // Index all class infos by their class name - wxClassInfo *info = *first; + wxClassInfo *info = first; while (info) { - if (info->className) - classTable.Put(info->className, (wxObject *)info); - info = info->next; + if (info->m_className) + classTable.Put(info->m_className, (wxObject *)info); + info = info->GetNext(); } // Set base pointers for each wxClassInfo - info = *first; + info = first; while (info) { if (info->GetBaseClassName1()) - info->baseInfo1 = (wxClassInfo *)classTable.Get(info->GetBaseClassName1()); + info->m_baseInfo1 = (wxClassInfo *)classTable.Get(info->GetBaseClassName1()); if (info->GetBaseClassName2()) - info->baseInfo2 = (wxClassInfo *)classTable.Get(info->GetBaseClassName2()); - info = info->next; + info->m_baseInfo2 = (wxClassInfo *)classTable.Get(info->GetBaseClassName2()); + info = info->m_next; } - *first = NULL; } void *wxLibrary::GetSymbol(const wxString& symbname) { -#ifdef __UNIX__ +#if defined(__UNIX__) return dlsym(m_handle, WXSTRINGCAST symbname); -#endif -#ifdef __WINDOWS__ - return GetProcAddress(m_handle, WXSTRINGCAST symbname); +#elif defined( __WINDOWS__ ) + return GetProcAddress((HINSTANCE) m_handle, WXSTRINGCAST symbname); +#elif defined( __WXMAC__ ) + Ptr symAddress ; + CFragSymbolClass symClass ; + Str255 symName ; + + strcpy( (char*) symName , symbname ) ; + c2pstr( (char*) symName ) ; + + if ( FindSymbol( (CFragConnectionID) m_handle , symName , &symAddress , &symClass ) == noErr ) + { + return symAddress ; + } #endif return NULL; } @@ -137,10 +160,15 @@ wxLibrary *wxLibraries::LoadLibrary(const wxString& name) wxString lib_name = name; wxNode *node; wxLibrary *lib; + wxClassInfo *old_sm_first; if ( (node = m_loaded.Find(name.GetData())) ) return ((wxLibrary *)node->Data()); + // If DLL shares data, this is necessary. + old_sm_first = wxClassInfo::sm_first; + wxClassInfo::sm_first = NULL; + #if defined(__UNIX__) lib_name.Prepend("./lib"); lib_name += ".so"; @@ -149,20 +177,46 @@ wxLibrary *wxLibraries::LoadLibrary(const wxString& name) void *handle = dlopen(WXSTRINGCAST lib_name, RTLD_LAZY); + printf("error = %s\n", dlerror()); + if (!handle) return NULL; #elif defined(__WINDOWS__) lib_name += ".dll"; - HMODULE handle = LoadLibrary(lib_name); +#ifdef UNICODE + HMODULE handle = LoadLibraryW(lib_name); +#else +#ifdef __WIN16__ + HMODULE handle = ::LoadLibrary(lib_name); +#else + HMODULE handle = LoadLibraryA(lib_name); +#endif +#endif if (!handle) return NULL; +#elif defined(__WXMAC__) + FSSpec myFSSpec ; + CFragConnectionID handle ; + Ptr myMainAddr ; + Str255 myErrName ; + + wxMacPathToFSSpec( lib_name , &myFSSpec ) ; + if (GetDiskFragment( &myFSSpec , 0 , kCFragGoesToEOF , "\p" , kPrivateCFragCopy , &handle , &myMainAddr , + myErrName ) != noErr ) + { + p2cstr( myErrName ) ; + wxASSERT_MSG( 1 , (char*)myErrName ) ; + return NULL ; + } #else return NULL; #endif lib = new wxLibrary((void *)handle); + wxClassInfo::sm_first = old_sm_first; + m_loaded.Append(name.GetData(), lib); return lib; } @@ -174,7 +228,7 @@ wxObject *wxLibraries::CreateObject(const wxString& path) while (node) { obj = ((wxLibrary *)node->Data())->CreateObject(path); - if (obj) + if (obj) return obj; node = node->Next();