LibraryLoader Class Reference

Class for helping loading of libraries or dlls. More...

List of all members.

Public Member Functions

 LibraryLoader ()
 Argument free Constructor.
 LibraryLoader (const SmartUtil::tstring &libraryName)
 Constructor loading the given library.
void load (const SmartUtil::tstring &libraryName)
 Actually loads library.
 ~LibraryLoader ()
 DTOR freeing up library.


Detailed Description

Class for helping loading of libraries or dlls.

Class normally meant for internal usage but can also be used publicly in user code.
Usage is whenever you need to ensure a dll is loaded instantiate a static object of this type, static to ensure Constructor is only called upon the first roundtrip of that code!
Then if that library is not loaded somewhere earlier in some other portions of your code it will load that library on demand the first time you need it!
Class is thread safe to ensure safe usage across multiple threads! Though if you need explicitly freeing of library (which you seldom need) class can be used explicitly allocated on the stack or something and freed up in DTOR of class!
Class is also reference counting instances of the same library and only actually calls LoadLibrary the first time it's instantiated with the same arguments! Though when LAST object with same arguments goes out of scope library is UNLOADED! Note also that library names are case sensitive in the refcounting part, also "path sensitive". Meaning it will differentiate between e.g. "%SYSTEM%/x.dll" and "x.dll" though there probably IS no real difference, this is a potential "hard to track" bug meaning always instantiate this class with the EXACT SAME arguments!
See exempel usage in WidgetRichTextBox


Constructor & Destructor Documentation

LibraryLoader ( const SmartUtil::tstring &  libraryName  ) 

Constructor loading the given library.

Constructor loading the given library unless library is loaded from before.
Note this class is "reference counting" libraries meaning you can create several instances of this class with the same library name and it will only load the library the first time, though when the LAST object is destroyed it will unload the given library!
Normally though you don't need to explicitly unload libraries meaning you can just allocate a static stack object of this type with the given library name anywhere you need to ensure your library must be loaded!

LibraryLoader (  ) 

Argument free Constructor.

Argument free Constructor, does NOTHING call load to actually load library!

~LibraryLoader (  ) 

DTOR freeing up library.

Normally there's not much need of explicitly freeing up a library meaning you can just allocate your library objects as static objects, also it won't unload library until LAST object with same argument is being destroyed!


Member Function Documentation

void load ( const SmartUtil::tstring &  libraryName  ) 

Actually loads library.

Call this one to actually load the given library or use Constructor taking SmartUtil::tstring argument which automatically loads library!

Back to SmartWin website
SourceForge.net Logo