123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "DLLRegister.h"
- using namespace Framework;
- // Inhalt der DLLDateien Klasse aus DLLDateien.h
- // Konstruktor
- DLLRegister::DLLRegister()
- {
- dlls = new Array< DLLDatei * >();
- ref = 1;
- }
- // Destruktor
- DLLRegister::~DLLRegister()
- {
- cs.lock();
- int anz = dlls->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- DLLDatei *tmp = dlls->get( i );
- if( tmp )
- {
- tmp->name->release();
- //FreeLibrary( tmp->handle );
- }
- delete tmp;
- }
- dlls->release();
- cs.unlock();
- }
- // nicht constant
- HINSTANCE DLLRegister::ladeDLL( char *name, char *pfad )
- {
- cs.lock();
- int anz = dlls->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- DLLDatei *tmp = dlls->get( i );
- if( tmp &&tmp->name->istGleich( name ) )
- {
- tmp->ref++;
- cs.unlock();
- return tmp->handle;
- }
- }
- HINSTANCE h = LoadLibrary( pfad );
- if( !h )
- {
- cs.unlock();
- return 0;
- }
- DLLDatei *dll = new DLLDatei();
- dll->name = new Text( name );
- dll->handle = h;
- dll->ref = 1;
- dlls->add( dll );
- cs.unlock();
- return h;
- }
- void DLLRegister::releaseDLL( char *name )
- {
- cs.lock();
- int anz = dlls->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- DLLDatei *tmp = dlls->get( i );
- if( tmp &&tmp->name->istGleich( name ) )
- {
- tmp->ref--;
- if( !tmp->ref )
- {
- tmp->name->release();
- //FreeLibrary( tmp->handle );
- delete tmp;
- dlls->remove( i );
- }
- cs.unlock();
- return;
- }
- }
- cs.unlock();
- }
- // Reference Counting
- DLLRegister *DLLRegister::getThis()
- {
- ref++;
- return this;
- }
- DLLRegister *DLLRegister::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|