#include "DLLRegister.h" using namespace Framework; // Inhalt der DLLDateien Klasse aus DLLDateien.h // Konstruktor DLLRegister::DLLRegister() : ReferenceCounter() { dlls = new Array< DLLDatei * >(); } // 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(); #ifndef _DEBUG FreeLibrary( tmp->handle ); #endif } 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(); #ifndef _DEBUG FreeLibrary( tmp->handle ); #endif delete tmp; dlls->remove( i ); } cs.unlock(); return; } } cs.unlock(); }