-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathModuleLoader.cpp
92 lines (77 loc) · 1.68 KB
/
ModuleLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (C) FlatGlobus(wtlbuilder@gmail.com) All rights reserved.
//
// This file is a part of the WTLBuilder.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#include "stdafx.h"
#include "ModuleLoader.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CModuleLoader::CModuleLoader()
{
Add(_T("Package.dll"));
}
CModuleLoader::~CModuleLoader()
{
Free();
}
void CModuleLoader::Load(void)
{
for(int i=0; i < modules.GetSize();i++)
{
modules[i].Load();
}
}
void CModuleLoader::Free(void)
{
for(int i=0; i < modules.GetSize();i++)
{
modules[i].Free();
}
}
void CModuleLoader::Add(const CString & name,BOOL DoLoad)
{
modules.Add(CModuleItem(name));
if(DoLoad==TRUE)
Load();
}
//////////////////////////////////////////////////////////////////////////
CModuleItem::CModuleItem(void):Handle(NULL), DllName(_T(""))
{
}
CModuleItem::CModuleItem(const CString & n):Handle(NULL), DllName(n)
{
}
CModuleItem::~CModuleItem(void)
{
Free();
}
BOOL CModuleItem::Load(void)
{
if (Handle)
return TRUE;
if(DllName.IsEmpty())
return FALSE;
Handle = ::LoadLibrary(DllName);
return IsLoaded();
}
void CModuleItem::Free(void)
{
if (IsLoaded())
::FreeLibrary(Handle);
Handle = NULL;
}
void CModuleItem::SetName(const CString & n)
{
DllName = n;
}
const CString & CModuleItem::GetName(void)
{
return DllName;
}
BOOL CModuleItem::IsLoaded(void)
{
return Handle != NULL;
}