4
4
const wchar_t *CClrHost::AppDomainManagerAssembly = L" mysql_managed_interface, Version=1.0.0.0, PublicKeyToken=71c4a5d4270bd29c" ;
5
5
const wchar_t *CClrHost::AppDomainManagerType = L" mysql_managed_interface.MySQLHostManager" ;
6
6
7
+ bool g_CLRHasBeenLoaded = false ;
8
+
7
9
// / <summary>
8
10
// / Initialize the host
9
11
// / </summary>
12
+
13
+
10
14
CClrHost::CClrHost () : m_started(false ), m_pClr(NULL ), m_pClrControl(NULL )
11
15
{
12
16
return ;
@@ -36,15 +40,15 @@ CClrHost::~CClrHost()
36
40
#pragma warning( disable : 4996 )
37
41
HRESULT CClrHost::FinalConstruct ()
38
42
{
39
- // load the CLR into the process
43
+ // load the CLR into the process
40
44
return CorBindToRuntimeEx (NULL ,
41
45
NULL ,
42
46
0 ,
43
47
CLSID_CLRRuntimeHost,
44
48
IID_ICLRRuntimeHost,
45
49
reinterpret_cast <LPVOID *>(&m_pClr));
46
50
47
- // // load the CLR into the process
51
+ // load the CLR into the process
48
52
// ICLRMetaHost *pMetaHost = NULL;
49
53
// ICLRMetaHostPolicy *pMetaHostPolicy = NULL;
50
54
// ICLRDebugging *pCLRDebugging = NULL;
@@ -60,22 +64,41 @@ HRESULT CClrHost::FinalConstruct()
60
64
// IEnumUnknown * pRtEnum = NULL;
61
65
// ICLRRuntimeInfo *info = NULL;
62
66
// ULONG fetched = 0;
67
+ // pMetaHost->EnumerateLoadedRuntimes(GetCurrentProcess(), &pRtEnum);
68
+ // while ((hr = pRtEnum->Next(1, (IUnknown **)&info, &fetched)) == S_OK && fetched > 0)
69
+ // {
70
+ // WCHAR strName[128];
71
+ // ZeroMemory(strName, sizeof(strName));
72
+ // DWORD len = 128;
73
+ // info->GetVersionString(strName, &len);
74
+ // hr = info->GetInterface(CLSID_CLRRuntimeHost,
75
+ // IID_ICLRRuntimeHost,
76
+ // reinterpret_cast<LPVOID *>(&m_pClr));
77
+ // if (!SUCCEEDED(hr))
78
+ // printf("hr failed....");
79
+
80
+ // }
81
+ // pRtEnum->Release();
82
+ // pRtEnum = NULL;
83
+
63
84
// pMetaHost->EnumerateInstalledRuntimes(&pRtEnum);
64
85
// while ((hr = pRtEnum->Next(1, (IUnknown **)&info, &fetched)) == S_OK && fetched > 0)
65
86
// {
66
87
// WCHAR strName[128];
67
88
// ZeroMemory(strName, sizeof(strName));
68
89
// DWORD len = 128;
69
90
// info->GetVersionString(strName, &len);
70
- // hr = info->GetInterface(CLSID_CLRRuntimeHost,
71
- // IID_ICLRRuntimeHost,
91
+ // hr = info->GetInterface(CLSID_CLRRuntimeHost,
92
+ // IID_ICLRRuntimeHost,
72
93
// reinterpret_cast<LPVOID *>(&m_pClr));
73
94
// if (!SUCCEEDED(hr))
74
95
// printf("hr failed....");
75
- //
96
+
76
97
// }
77
98
// pRtEnum->Release();
78
- // return S_OK;
99
+
100
+
101
+ return S_OK;
79
102
}
80
103
81
104
// / <summary>
@@ -150,14 +173,18 @@ STDMETHODIMP CClrHost::raw_Start()
150
173
// we should have bound to the runtime, but not yet started it upon entry
151
174
_ASSERTE (m_pClr != NULL );
152
175
_ASSERTE (!m_started);
176
+
153
177
if (m_pClr == NULL )
154
178
return E_FAIL;
155
179
156
180
// get the CLR control object
157
181
HRESULT hrClrControl = m_pClr->GetCLRControl (&m_pClrControl);
158
182
if (FAILED (hrClrControl))
159
183
return hrClrControl;
160
-
184
+
185
+ // set ourselves up as the host control
186
+ HRESULT hrHostControl = m_pClr->SetHostControl (static_cast <IHostControl *>(this ));
187
+
161
188
// get the host protection manager
162
189
ICLRHostProtectionManager *pHostProtectionManager = NULL ;
163
190
HRESULT hrGetProtectionManager = m_pClrControl->GetCLRManager (
@@ -174,27 +201,20 @@ STDMETHODIMP CClrHost::raw_Start()
174
201
if (FAILED (hrHostProtection))
175
202
return hrHostProtection;
176
203
177
- // set ourselves up as the host control
178
- HRESULT hrHostControl = m_pClr->SetHostControl (static_cast <IHostControl *>(this ));
179
- if (FAILED (hrHostControl))
180
- return hrHostControl;
181
204
182
205
// setup the AppDomainManager
183
206
HRESULT hrSetAdm = m_pClrControl->SetAppDomainManagerType (AppDomainManagerAssembly, AppDomainManagerType);
184
207
if (FAILED (hrSetAdm))
185
208
return hrSetAdm;
186
209
187
-
188
-
189
-
210
+ // mark as started
211
+ m_started = true ;
190
212
191
213
// finally, start the runtime
192
214
HRESULT hrStart = m_pClr->Start ();
193
215
if (FAILED (hrStart))
194
216
return hrStart;
195
217
196
- // mark as started
197
- m_started = true ;
198
218
return S_OK;
199
219
}
200
220
@@ -205,7 +225,6 @@ STDMETHODIMP CClrHost::raw_Start()
205
225
STDMETHODIMP CClrHost::raw_Stop ()
206
226
{
207
227
_ASSERTE (m_started);
208
-
209
228
// first send a Dispose call to the managed hosts
210
229
for (AppDomainManagerMap::iterator iAdm = m_appDomainManagers.begin (); iAdm != m_appDomainManagers.end (); iAdm++)
211
230
iAdm->second ->raw_Dispose ();
0 commit comments