]> git.saurik.com Git - wxWidgets.git/blob - src/common/dynload.cpp
fad9d7515a7a50f206bd2dd57800c36378ab9ad7
[wxWidgets.git] / src / common / dynload.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dynload.cpp
3 // Purpose: Dynamic loading framework
4 // Author: Ron Lee, David Falkinder, Vadim Zeitlin and a cast of 1000's
5 // (derived in part from dynlib.cpp (c) 1998 Guilhem Lavaux)
6 // Modified by:
7 // Created: 03/12/01
8 // RCS-ID: $Id$
9 // Copyright: (c) 2001 Ron Lee <ron@debian.org>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifdef __GNUG__
14 #pragma implementation "dynload.h"
15 #endif
16
17 // ----------------------------------------------------------------------------
18 // headers
19 // ----------------------------------------------------------------------------
20
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_DYNAMIC_LOADER
28
29 #ifdef __WINDOWS__
30 #include "wx/msw/private.h"
31 #endif
32
33 #ifndef WX_PRECOMP
34 #include "wx/log.h"
35 #include "wx/intl.h"
36 #include "wx/hash.h"
37 #include "wx/utils.h"
38 #endif
39
40 #include "wx/filename.h" // for SplitPath()
41 #include "wx/strconv.h"
42
43 #include "wx/dynload.h"
44 #include "wx/module.h"
45
46 #if defined(__DARWIN__)
47 /* Porting notes:
48 * The dlopen port is a port from dl_next.xs by Anno Siegel.
49 * dl_next.xs is itself a port from dl_dlopen.xs by Paul Marquess.
50 * The method used here is just to supply the sun style dlopen etc.
51 * functions in terms of Darwin NS*.
52 */
53 void *dlopen(const char *path, int mode /* mode is ignored */);
54 void *dlsym(void *handle, const char *symbol);
55 int dlclose(void *handle);
56 const char *dlerror(void);
57 #endif
58
59 // ============================================================================
60 // implementation
61 // ============================================================================
62
63 // ---------------------------------------------------------------------------
64 // wxDynamicLibrary
65 // ---------------------------------------------------------------------------
66
67 //FIXME: This class isn't really common at all, it should be moved into
68 // platform dependent files.
69
70 #if defined(__WINDOWS__) || defined(__WXPM__) || defined(__EMX__)
71 const wxChar *wxDynamicLibrary::ms_dllext = _T(".dll");
72 #elif defined(__UNIX__)
73 #if defined(__HPUX__)
74 const wxChar *wxDynamicLibrary::ms_dllext = _T(".sl");
75 #else
76 const wxChar *wxDynamicLibrary::ms_dllext = _T(".so");
77 #endif
78 #endif
79
80 wxDllType wxDynamicLibrary::GetProgramHandle()
81 {
82 #if defined( HAVE_DLOPEN ) && !defined(__EMX__)
83 return dlopen(0, RTLD_LAZY);
84 #elif defined (HAVE_SHL_LOAD)
85 return PROG_HANDLE;
86 #else
87 wxFAIL_MSG( wxT("This method is not implemented under Windows or OS/2"));
88 return 0;
89 #endif
90 }
91
92 bool wxDynamicLibrary::Load(wxString libname, int flags)
93 {
94 wxASSERT_MSG(m_handle == 0, _T("Library already loaded."));
95
96 // add the proper extension for the DLL ourselves unless told not to
97 if ( !(flags & wxDL_VERBATIM) )
98 {
99 // and also check that the libname doesn't already have it
100 wxString ext;
101 wxFileName::SplitPath(libname, NULL, NULL, &ext);
102 if ( ext.empty() )
103 {
104 libname += GetDllExt();
105 }
106 }
107
108 // different ways to load a shared library
109 //
110 // FIXME: should go to the platform-specific files!
111 #if defined(__WXMAC__) && !defined(__DARWIN__)
112 FSSpec myFSSpec;
113 Ptr myMainAddr;
114 Str255 myErrName;
115
116 wxMacFilename2FSSpec( libname , &myFSSpec );
117
118 if( GetDiskFragment( &myFSSpec,
119 0,
120 kCFragGoesToEOF,
121 "\p",
122 kPrivateCFragCopy,
123 &m_handle,
124 &myMainAddr,
125 myErrName ) != noErr )
126 {
127 p2cstr( myErrName );
128 wxLogSysError( _("Failed to load shared library '%s' Error '%s'"),
129 libname.c_str(),
130 (char*)myErrName );
131 m_handle = 0;
132 }
133
134 #elif defined(__WXPM__) || defined(__EMX__)
135 char err[256] = "";
136 DosLoadModule(err, sizeof(err), libname.c_str(), &m_handle);
137
138 #elif defined(HAVE_DLOPEN) || defined(__DARWIN__)
139
140 #if defined(__VMS) || defined(__DARWIN__)
141 m_handle = dlopen(libname.c_str(), 0); // The second parameter is ignored
142 #else // !__VMS && !__DARWIN__
143 int rtldFlags = 0;
144
145 if ( flags & wxDL_LAZY )
146 {
147 wxASSERT_MSG( (flags & wxDL_NOW) == 0,
148 _T("wxDL_LAZY and wxDL_NOW are mutually exclusive.") );
149 #ifdef RTLD_LAZY
150 rtldFlags |= RTLD_LAZY;
151 #else
152 wxLogDebug(_T("wxDL_LAZY is not supported on this platform"));
153 #endif
154 }
155 else if ( flags & wxDL_NOW )
156 {
157 #ifdef RTLD_NOW
158 rtldFlags |= RTLD_NOW;
159 #else
160 wxLogDebug(_T("wxDL_NOW is not supported on this platform"));
161 #endif
162 }
163
164 if ( flags & wxDL_GLOBAL )
165 {
166 #ifdef RTLD_GLOBAL
167 rtldFlags |= RTLD_GLOBAL;
168 #else
169 wxLogDebug(_T("RTLD_GLOBAL is not supported on this platform."));
170 #endif
171 }
172
173 m_handle = dlopen(libname.fn_str(), rtldFlags);
174 #endif // __VMS || __DARWIN__ ?
175
176 #elif defined(HAVE_SHL_LOAD)
177 int shlFlags = 0;
178
179 if( flags & wxDL_LAZY )
180 {
181 wxASSERT_MSG( (flags & wxDL_NOW) == 0,
182 _T("wxDL_LAZY and wxDL_NOW are mutually exclusive.") );
183 shlFlags |= BIND_DEFERRED;
184 }
185 else if( flags & wxDL_NOW )
186 {
187 shlFlags |= BIND_IMMEDIATE;
188 }
189 m_handle = shl_load(libname.fn_str(), BIND_DEFERRED, 0);
190
191 #elif defined(__WINDOWS__)
192 m_handle = ::LoadLibrary(libname.c_str());
193 #else
194 #error "runtime shared lib support not implemented on this platform"
195 #endif
196
197 if ( m_handle == 0 )
198 {
199 wxString msg(_("Failed to load shared library '%s'"));
200 #if defined(HAVE_DLERROR) && !defined(__EMX__)
201
202 #if wxUSE_UNICODE
203 wxWCharBuffer buffer = wxConvLocal.cMB2WC( dlerror() );
204 const wxChar *err = buffer;
205 #else
206 const wxChar *err = dlerror();
207 #endif
208
209 if( err )
210 wxLogError( msg, err );
211 #else
212 wxLogSysError( msg, libname.c_str() );
213 #endif
214 }
215
216 return IsLoaded();
217 }
218
219 void wxDynamicLibrary::Unload()
220 {
221 if( IsLoaded() )
222 {
223 #if defined(__WXPM__) || defined(__EMX__)
224 DosFreeModule( m_handle );
225 #elif defined(HAVE_DLOPEN) || defined(__DARWIN__)
226 dlclose( m_handle );
227 #elif defined(HAVE_SHL_LOAD)
228 shl_unload( m_handle );
229 #elif defined(__WINDOWS__)
230 ::FreeLibrary( m_handle );
231 #elif defined(__WXMAC__) && !defined(__DARWIN__)
232 CloseConnection( (CFragConnectionID*) &m_handle );
233 #else
234 #error "runtime shared lib support not implemented"
235 #endif
236 m_handle = 0;
237 }
238 }
239
240 void *wxDynamicLibrary::GetSymbol(const wxString &name, bool *success) const
241 {
242 wxCHECK_MSG( IsLoaded(), NULL,
243 _T("Can't load symbol from unloaded library") );
244
245 bool failed = FALSE;
246 void *symbol = 0;
247
248 #if defined(__WXMAC__) && !defined(__DARWIN__)
249 Ptr symAddress;
250 CFragSymbolClass symClass;
251 Str255 symName;
252 #if TARGET_CARBON
253 c2pstrcpy( (StringPtr) symName, name );
254 #else
255 strcpy( (char *)symName, name );
256 c2pstr( (char *)symName );
257 #endif
258 if( FindSymbol( dllHandle, symName, &symAddress, &symClass ) == noErr )
259 symbol = (void *)symAddress;
260
261 #elif defined(__WXPM__) || defined(__EMX__)
262 DosQueryProcAddr( m_handle, 1L, name.c_str(), (PFN*)symbol );
263
264 #elif defined(HAVE_DLOPEN) || defined(__DARWIN__)
265 symbol = dlsym( m_handle, name.fn_str() );
266
267 #elif defined(HAVE_SHL_LOAD)
268 // use local variable since shl_findsym modifies the handle argument
269 // to indicate where the symbol was found (GD)
270 wxDllType the_handle = m_handle;
271 if( shl_findsym( &the_handle, name.fn_str(), TYPE_UNDEFINED, &symbol ) != 0 )
272 symbol = 0;
273
274 #elif defined(__WINDOWS__)
275 symbol = (void*) ::GetProcAddress( m_handle, name.mb_str() );
276
277 #else
278 #error "runtime shared lib support not implemented"
279 #endif
280
281 if ( !symbol )
282 {
283 #if defined(HAVE_DLERROR) && !defined(__EMX__)
284
285 #if wxUSE_UNICODE
286 wxWCharBuffer buffer = wxConvLocal.cMB2WC( dlerror() );
287 const wxChar *err = buffer;
288 #else
289 const wxChar *err = dlerror();
290 #endif
291
292 if( err )
293 {
294 wxLogError(wxT("%s"), err);
295 }
296 #else
297 failed = TRUE;
298 wxLogSysError(_("Couldn't find symbol '%s' in a dynamic library"),
299 name.c_str());
300 #endif
301 }
302 if( success )
303 *success = !failed;
304
305 return symbol;
306 }
307
308
309 /*static*/
310 wxString wxDynamicLibrary::CanonicalizeName(const wxString& name,
311 wxDynamicLibraryCategory cat)
312 {
313 #ifdef __UNIX__
314 if ( cat == wxDL_MODULE )
315 return name + GetDllExt();
316 else
317 return wxString(_T("lib")) + name + GetDllExt();
318 #else
319 return name + GetDllExt();
320 #endif
321 }
322
323 /*static*/
324 wxString wxDynamicLibrary::CanonicalizePluginName(const wxString& name,
325 wxPluginCategory cat)
326 {
327 wxString suffix;
328 if ( cat == wxDL_PLUGIN_GUI )
329 {
330 suffix = wxString::FromAscii(
331 #if defined(__WXMSW__)
332 "msw"
333 #elif defined(__WXGTK__)
334 "gtk"
335 #elif defined(__WXMGL__)
336 "mgl"
337 #elif defined(__WXMOTIF__)
338 "motif"
339 #elif defined(__WXOS2__)
340 "pm"
341 #elif defined(__WXX11__)
342 "x11"
343 #elif defined(__WXMAC__)
344 "mac"
345 #elif defined(__WXCOCOA__)
346 "cocoa"
347 #endif
348 );
349
350 #ifdef __WXUNIVERSAL__
351 suffix << _T("univ");
352 #endif
353 }
354 #if wxUSE_UNICODE
355 suffix << _T('u');
356 #endif
357 #ifdef __WXDEBUG__
358 suffix << _T('d');
359 #endif
360
361 if ( !suffix.empty() )
362 suffix = wxString(_T("_")) + suffix;
363
364 #ifdef __UNIX__
365 #if (wxMINOR_VERSION % 2) == 0
366 #define wxDLLVER(x,y,z) "-" #x "." #y
367 #else
368 #define wxDLLVER(x,y,z) "-" #x "." #y "." #z
369 #endif
370 #else
371 #if (wxMINOR_VERSION % 2) == 0
372 #define wxDLLVER(x,y,z) #x #y
373 #else
374 #define wxDLLVER(x,y,z) #x #y #z
375 #endif
376 #endif
377 suffix << wxString::FromAscii(wxDLLVER(wxMAJOR_VERSION, wxMINOR_VERSION,
378 wxRELEASE_NUMBER));
379 #undef wxDLLVER
380
381 return CanonicalizeName(name + suffix, wxDL_MODULE);
382 }
383
384 /*static*/
385 wxString wxDynamicLibrary::GetPluginsDirectory()
386 {
387 #ifdef __UNIX__
388 wxString format = wxGetInstallPrefix();
389 format << wxFILE_SEP_PATH
390 << wxT("lib") << wxFILE_SEP_PATH
391 << wxT("wx") << wxFILE_SEP_PATH
392 << wxT("%i.%i");
393 wxString dir;
394 dir.Printf(format.c_str(), wxMAJOR_VERSION, wxMINOR_VERSION);
395 return dir;
396 #else
397 return wxEmptyString;
398 #endif
399 }
400
401
402 // ---------------------------------------------------------------------------
403 // wxPluginLibrary
404 // ---------------------------------------------------------------------------
405
406
407 wxDLImports* wxPluginLibrary::ms_classes = NULL;
408
409 class wxPluginLibraryModule : public wxModule
410 {
411 public:
412 wxPluginLibraryModule() { }
413
414 // TODO: create ms_classes on demand, why always preallocate it?
415 virtual bool OnInit()
416 {
417 wxPluginLibrary::ms_classes = new wxDLImports(wxKEY_STRING);
418 wxPluginManager::CreateManifest();
419 return TRUE;
420 }
421
422 virtual void OnExit()
423 {
424 delete wxPluginLibrary::ms_classes;
425 wxPluginLibrary::ms_classes = NULL;
426 wxPluginManager::ClearManifest();
427 }
428
429 private:
430 DECLARE_DYNAMIC_CLASS(wxPluginLibraryModule )
431 };
432
433 IMPLEMENT_DYNAMIC_CLASS(wxPluginLibraryModule, wxModule)
434
435
436 wxPluginLibrary::wxPluginLibrary(const wxString &libname, int flags)
437 : m_linkcount(1)
438 , m_objcount(0)
439 {
440 m_before = wxClassInfo::sm_first;
441 Load( libname, flags );
442 m_after = wxClassInfo::sm_first;
443
444 if( m_handle != 0 )
445 {
446 UpdateClassInfo();
447 RegisterModules();
448 }
449 else
450 {
451 // Flag us for deletion
452 --m_linkcount;
453 }
454 }
455
456 wxPluginLibrary::~wxPluginLibrary()
457 {
458 if( m_handle != 0 )
459 {
460 UnregisterModules();
461 RestoreClassInfo();
462 }
463 }
464
465 wxPluginLibrary *wxPluginLibrary::RefLib()
466 {
467 wxCHECK_MSG( m_linkcount > 0, NULL,
468 _T("Library had been already deleted!") );
469
470 ++m_linkcount;
471 return this;
472 }
473
474 bool wxPluginLibrary::UnrefLib()
475 {
476 wxASSERT_MSG( m_objcount == 0,
477 _T("Library unloaded before all objects were destroyed") );
478
479 if ( --m_linkcount == 0 )
480 {
481 delete this;
482 return TRUE;
483 }
484
485 return FALSE;
486 }
487
488 // ------------------------
489 // Private methods
490 // ------------------------
491
492 void wxPluginLibrary::UpdateClassInfo()
493 {
494 wxClassInfo *info;
495 wxHashTable *t = wxClassInfo::sm_classTable;
496
497 // FIXME: Below is simply a cut and paste specialisation of
498 // wxClassInfo::InitializeClasses. Once this stabilises,
499 // the two should probably be merged.
500 //
501 // Actually it's becoming questionable whether we should merge
502 // this info with the main ClassInfo tables since we can nearly
503 // handle this completely internally now and it does expose
504 // certain (minimal % user_stupidy) risks.
505
506 for(info = m_after; info != m_before; info = info->m_next)
507 {
508 if( info->m_className )
509 {
510 if( t->Get(info->m_className) == 0 )
511 t->Put(info->m_className, (wxObject *)info);
512
513 // Hash all the class names into a local table too so
514 // we can quickly find the entry they correspond to.
515 (*ms_classes)[info->m_className] = this;
516 }
517 }
518
519 #if wxUSE_EXTENDED_RTTI == 0
520 for(info = m_after; info != m_before; info = info->m_next)
521 {
522 if( info->m_baseClassName1 )
523 info->m_baseInfo1 = (wxClassInfo *)t->Get(info->m_baseClassName1);
524 if( info->m_baseClassName2 )
525 info->m_baseInfo2 = (wxClassInfo *)t->Get(info->m_baseClassName2);
526 }
527 #endif
528 }
529
530 void wxPluginLibrary::RestoreClassInfo()
531 {
532 wxClassInfo *info;
533
534 for(info = m_after; info != m_before; info = info->m_next)
535 {
536 wxClassInfo::sm_classTable->Delete(info->m_className);
537 ms_classes->erase(ms_classes->find(info->m_className));
538 }
539
540 if( wxClassInfo::sm_first == m_after )
541 wxClassInfo::sm_first = m_before;
542 else
543 {
544 info = wxClassInfo::sm_first;
545 while( info->m_next && info->m_next != m_after ) info = info->m_next;
546
547 wxASSERT_MSG( info, _T("ClassInfo from wxPluginLibrary not found on purge"));
548
549 info->m_next = m_before;
550 }
551 }
552
553 void wxPluginLibrary::RegisterModules()
554 {
555 // Plugin libraries might have wxModules, Register and initialise them if
556 // they do.
557 //
558 // Note that these classes are NOT included in the reference counting since
559 // it's implicit that they will be unloaded if and when the last handle to
560 // the library is. We do have to keep a copy of the module's pointer
561 // though, as there is currently no way to Unregister it without it.
562
563 wxASSERT_MSG( m_linkcount == 1,
564 _T("RegisterModules should only be called for the first load") );
565
566 for ( wxClassInfo *info = m_after; info != m_before; info = info->m_next)
567 {
568 if( info->IsKindOf(CLASSINFO(wxModule)) )
569 {
570 wxModule *m = wxDynamicCast(info->CreateObject(), wxModule);
571
572 wxASSERT_MSG( m, _T("wxDynamicCast of wxModule failed") );
573
574 m_wxmodules.push_back(m);
575 wxModule::RegisterModule(m);
576 }
577 }
578
579 // FIXME: Likewise this is (well was) very similar to InitializeModules()
580
581 for ( wxModuleList::iterator it = m_wxmodules.begin();
582 it != m_wxmodules.end();
583 ++it)
584 {
585 if( !(*it)->Init() )
586 {
587 wxLogDebug(_T("wxModule::Init() failed for wxPluginLibrary"));
588
589 // XXX: Watch this, a different hash implementation might break it,
590 // a good hash implementation would let us fix it though.
591
592 // The name of the game is to remove any uninitialised modules and
593 // let the dtor Exit the rest on shutdown, (which we'll initiate
594 // shortly).
595
596 wxModuleList::iterator oldNode = m_wxmodules.end();
597 do {
598 ++it;
599 if( oldNode != m_wxmodules.end() )
600 m_wxmodules.erase(oldNode);
601 wxModule::UnregisterModule( *it );
602 oldNode = it;
603 } while( it != m_wxmodules.end() );
604
605 --m_linkcount; // Flag us for deletion
606 break;
607 }
608 }
609 }
610
611 void wxPluginLibrary::UnregisterModules()
612 {
613 wxModuleList::iterator it;
614
615 for ( it = m_wxmodules.begin(); it != m_wxmodules.end(); ++it )
616 (*it)->Exit();
617
618 for ( it = m_wxmodules.begin(); it != m_wxmodules.end(); ++it )
619 wxModule::UnregisterModule( *it );
620
621 WX_CLEAR_LIST(wxModuleList, m_wxmodules);
622 }
623
624
625 // ---------------------------------------------------------------------------
626 // wxPluginManager
627 // ---------------------------------------------------------------------------
628
629 wxDLManifest* wxPluginManager::ms_manifest = NULL;
630
631 // ------------------------
632 // Static accessors
633 // ------------------------
634
635 wxPluginLibrary *
636 wxPluginManager::LoadLibrary(const wxString &libname, int flags)
637 {
638 wxString realname(libname);
639
640 if( !(flags & wxDL_VERBATIM) )
641 realname += wxDynamicLibrary::GetDllExt();
642
643 wxPluginLibrary *entry;
644
645 if ( flags & wxDL_NOSHARE )
646 {
647 entry = NULL;
648 }
649 else
650 {
651 entry = FindByName(realname);
652 }
653
654 if ( entry )
655 {
656 wxLogTrace(_T("dll"),
657 _T("LoadLibrary(%s): already loaded."), realname.c_str());
658
659 entry->RefLib();
660 }
661 else
662 {
663 entry = new wxPluginLibrary( libname, flags );
664
665 if ( entry->IsLoaded() )
666 {
667 (*ms_manifest)[realname] = entry;
668
669 wxLogTrace(_T("dll"),
670 _T("LoadLibrary(%s): loaded ok."), realname.c_str());
671
672 }
673 else
674 {
675 wxLogTrace(_T("dll"),
676 _T("LoadLibrary(%s): failed to load."), realname.c_str());
677
678 // we have created entry just above
679 if ( !entry->UnrefLib() )
680 {
681 // ... so UnrefLib() is supposed to delete it
682 wxFAIL_MSG( _T("Currently linked library is not loaded?") );
683 }
684
685 entry = NULL;
686 }
687 }
688
689 return entry;
690 }
691
692 bool wxPluginManager::UnloadLibrary(const wxString& libname)
693 {
694 wxString realname = libname;
695
696 wxPluginLibrary *entry = FindByName(realname);
697
698 if ( !entry )
699 {
700 realname += wxDynamicLibrary::GetDllExt();
701
702 entry = FindByName(realname);
703 }
704
705 if ( !entry )
706 {
707 wxLogDebug(_T("Attempt to unload library '%s' which is not loaded."),
708 libname.c_str());
709
710 return FALSE;
711 }
712
713 wxLogTrace(_T("dll"), _T("UnloadLibrary(%s)"), realname.c_str());
714
715 if ( !entry->UnrefLib() )
716 {
717 // not really unloaded yet
718 return FALSE;
719 }
720
721 ms_manifest->erase(ms_manifest->find(realname));
722
723 return TRUE;
724 }
725
726 #if WXWIN_COMPATIBILITY_2_2
727 wxPluginLibrary *wxPluginManager::GetObjectFromHandle(wxDllType handle)
728 {
729 for ( wxDLManifest::iterator i = ms_manifest->begin();
730 i != ms_manifest->end();
731 ++i )
732 {
733 wxPluginLibrary * const lib = i->second;
734
735 if ( lib->GetLibHandle() == handle )
736 return lib;
737 }
738
739 return NULL;
740 }
741 #endif // WXWIN_COMPATIBILITY_2_2
742
743 // ------------------------
744 // Class implementation
745 // ------------------------
746
747 bool wxPluginManager::Load(const wxString &libname, int flags)
748 {
749 m_entry = wxPluginManager::LoadLibrary(libname, flags);
750
751 return IsLoaded();
752 }
753
754 void wxPluginManager::Unload()
755 {
756 wxCHECK_RET( m_entry, _T("unloading an invalid wxPluginManager?") );
757
758 for ( wxDLManifest::iterator i = ms_manifest->begin();
759 i != ms_manifest->end();
760 ++i )
761 {
762 if ( i->second == m_entry )
763 {
764 ms_manifest->erase(i);
765 break;
766 }
767 }
768
769 m_entry->UnrefLib();
770
771 m_entry = NULL;
772 }
773
774 // ---------------------------------------------------------------------------
775 // wxDllLoader (all these methods are static)
776 // ---------------------------------------------------------------------------
777
778 #if WXWIN_COMPATIBILITY_2_2
779
780 wxDllType wxDllLoader::LoadLibrary(const wxString &name, bool *success)
781 {
782 wxPluginLibrary *p = wxPluginManager::LoadLibrary
783 (
784 name,
785 wxDL_DEFAULT | wxDL_VERBATIM | wxDL_NOSHARE
786 );
787
788 if ( success )
789 *success = p != NULL;
790
791 return p ? p->GetLibHandle() : 0;
792 }
793
794 void wxDllLoader::UnloadLibrary(wxDllType handle)
795 {
796 wxPluginLibrary *p = wxPluginManager::GetObjectFromHandle(handle);
797
798 wxCHECK_RET( p, _T("Unloading a library not loaded with wxDllLoader?") );
799
800 p->UnrefLib();
801 }
802
803 void *
804 wxDllLoader::GetSymbol(wxDllType dllHandle, const wxString &name, bool *success)
805 {
806 wxPluginLibrary *p = wxPluginManager::GetObjectFromHandle(dllHandle);
807
808 if ( !p )
809 {
810 wxFAIL_MSG( _T("Using a library not loaded with wxDllLoader?") );
811
812 if ( success )
813 *success = FALSE;
814
815 return NULL;
816 }
817
818 return p->GetSymbol(name, success);
819 }
820
821 #endif // WXWIN_COMPATIBILITY_2_2
822
823 #endif // wxUSE_DYNAMIC_LOADER
824