12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #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(const char* name, const 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(const 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();
- }
|