@@ -31,8 +31,6 @@ CADMHostModule _AtlModule;
31
31
32
32
CClrHost::CClrHost () : m_started(false ), m_pClrControl(NULL )
33
33
{
34
-
35
-
36
34
return ;
37
35
}
38
36
@@ -41,13 +39,13 @@ CClrHost::CClrHost() : m_started(false), m_pClrControl(NULL)
41
39
// / </summary>
42
40
CClrHost::~CClrHost ()
43
41
{
44
- // free the AppDomainManagers
45
- for (AppDomainManagerMap::iterator iAdm = m_appDomainManagers.begin (); iAdm != m_appDomainManagers.end (); iAdm++)
46
- iAdm->second ->Release ();
42
+ // // free the AppDomainManagers
43
+ // for (AppDomainManagerMap::iterator iAdm = m_appDomainManagers.begin(); iAdm != m_appDomainManagers.end(); iAdm++)
44
+ // iAdm->second->Release();
47
45
48
- // release the CLR
49
- if (m_pClrControl != NULL )
50
- m_pClrControl->Release ();
46
+ // // release the CLR
47
+ // if (m_pClrControl != NULL)
48
+ // m_pClrControl->Release();
51
49
return ;
52
50
}
53
51
@@ -154,7 +152,6 @@ HRESULT CClrHost::FinalConstruct()
154
152
// Enumeration example from COM books.
155
153
156
154
bool runtimesLoaded = false ;
157
- // pMetaHost->EnumerateLoadedRuntimes(GetCurrentProcess(), &pRtEnum);
158
155
159
156
WCHAR strName[MAXSTRING];
160
157
DWORD len = MAXSTRING;
@@ -164,6 +161,10 @@ HRESULT CClrHost::FinalConstruct()
164
161
165
162
166
163
pMetaHost->EnumerateLoadedRuntimes (GetCurrentProcess (), &pRtEnum);
164
+ if (pRtEnum == NULL )
165
+ {
166
+ return E_POINTER;
167
+ }
167
168
while ((hr = pRtEnum->Next (1 , (IUnknown **)&info, &fetched)) == S_OK && fetched > 0 )
168
169
{
169
170
// If the runtime is loaded in MySQL already, then we may not have control over it.
@@ -407,43 +408,38 @@ STDMETHODIMP CClrHost::raw_GetManagedHost(long appDomain, BSTR clr, IManagedHost
407
408
}
408
409
}
409
410
410
- STDMETHODIMP CClrHost::raw_GetSpecificManagedHost (BSTR clr, IManagedHost **ppHost)
411
- {
412
- _ASSERTE (m_started);
413
-
414
- if (ppHost == NULL )
415
- return E_POINTER;
416
-
417
- // get the AppDomainManager for the specified domain
418
- auto iHost = m_NewlyCreatedAppDomains[clr];
419
-
420
- // see if we've got a host
421
- if (iHost == NULL )
422
- {
423
- *ppHost = NULL ;
424
- return E_NOMANAGEDHOST;
425
- }
426
- else
427
- {
428
- *ppHost = iHost;
429
- (*ppHost)->AddRef ();
430
- return S_OK;
431
- }
432
- }
433
411
434
412
435
413
// IHostGCManager
436
414
STDMETHODIMP CClrHost::SuspensionEnding (DWORD generation){ return S_OK; }
437
415
STDMETHODIMP CClrHost::SuspensionStarting (){ return S_OK; }
438
416
STDMETHODIMP CClrHost::ThreadIsBlockingForSuspension (){ return S_OK; }
439
417
440
- STDMETHODIMP CClrHost::raw_CreateAppDomainForQuery (BSTR FnName, BSTR *pRetVal )
418
+ STDMETHODIMP CClrHost::raw_CreateAppDomainForQuery (BSTR FnName, IManagedHost **ppHost )
441
419
{
442
420
IManagedHostPtr pAppMgr = this ->GetDefaultManagedHost ();
443
421
auto clrVersion = pAppMgr->GetAssemblyCLRVersion (FnName);
444
422
auto domManager = this ->m_appDomainManagers [std::wstring (clrVersion)];
445
423
IManagedHostPtr pNewDomain = domManager->CreateAppDomain (FnName);
446
- *pRetVal = (BSTR)pNewDomain->GetAppDomainName ;
447
- this ->m_NewlyCreatedAppDomains [std::wstring (*pRetVal)] = pNewDomain;
424
+ *ppHost = pNewDomain;
425
+ (*ppHost)->AddRef ();
426
+ // Check to see if the appdmain stored in our default domain is one we have a ref to.
427
+ return S_OK;
428
+ }
429
+
430
+ STDMETHODIMP CClrHost::raw_UnloadAppDomain (IManagedHost * managedHost, VARIANT_BOOL * pRetVal)
431
+ {
432
+ try
433
+ {
434
+ auto appdomainName = managedHost->GetAppDomainName ;
435
+ auto appDomainCLR = managedHost->GetCLR ();
436
+ // We're good to access this map since we're not writing to it once we've bound the CLRs
437
+ this ->m_appDomainManagers [std::wstring (appDomainCLR)]->Unload (appdomainName);
438
+ }
439
+ catch (const _com_error &e)
440
+ {
441
+ // I'm alright with there being nothing here.
442
+ }
448
443
return S_OK;
449
- }
444
+
445
+ }
0 commit comments