我正在尝试创建一个ICLRAppDomainResourceMonitor接口的实例,但是我没有发现是什么coclass实现它的线索。如果没有这些知识,我就不能创建coclass的对象实例并从coclass对象中检索该接口。
有人能在这方面帮我吗?非常感谢。
发布于 2010-11-09 19:16:07
在上面的代码中,我们可以成功地创建ICLRAppDomainResourceMonitor实例。
实际上,我正在尝试获取在同一系统上运行的每个.NET 4.0进程的每个AppDomain的属性值。
我尝试了下面的代码来获取AppDomain的数据:
void getAttributeValues(struct processIDMap *NETProcessID){ //NETProcessID is collection of .NET 4.0 process running on system
ICorPublishAppDomain* appDomains[1];
ULONG aFetched = 1;
ICLRMetaHost *meta = NULL;
ICLRRuntimeInfo *info = NULL;
ICLRRuntimeHost *host = NULL;
ICLRControl *control = NULL;
ICLRAppDomainResourceMonitor *monitor = NULL;
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (void **)&meta);
if (! SUCCEEDED(hr))
printf("hr failed....");
struct processIDMap *tempStruct = NETProcessID;
while(tempStruct != NULL ){
HANDLE pHandle = NULL;
IEnumUnknown * pRtEnum = NULL;
DWORD Aid = 0;
ULONGLONG bytes = 0;
ULONG fetched = 0;
pHandle = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,tempStruct->PID);
hr = meta->EnumerateLoadedRuntimes(pHandle, &pRtEnum);
if (! SUCCEEDED(hr))
printf("hr failed....");
while ((hr = pRtEnum->Next(1,(IUnknown **)&info,&fetched)) == S_OK && fetched > 0){
hr = info->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void **)&host);
if (! SUCCEEDED(hr))
printf("hr failed....");
hr = host->GetCLRControl(&control);
if (! SUCCEEDED(hr))
printf("hr failed....");
hr = control->GetCLRManager(IID_ICLRAppDomainResourceMonitor, (void **)&monitor);
if (! SUCCEEDED(hr))
printf("hr failed....");
hr = monitor->GetCurrentAllocated(Aid, &bytes);
if (! SUCCEEDED(hr))
printf("hr failed....");
}
//info->Release();
//control->Release();
//monitor->Release();
//host->Release();
tempStruct = tempStruct->next;
pRtEnum->Release();
CloseHandle(pHandle);
}
meta->Release();}
但接口monitor->GetCurrentAllocated(Aid,&bytes)返回hr的值为-2146234348,即COR_E_APPDOMAINUNLOADED
请提供您的意见。
谢谢,
发布于 2010-11-01 12:27:33
有了从ICLRRuntimeHost::GetCLRControl生成的ICLRControl之后,使用IID_ICLRAppDomainResourceMonitor为所需的接口执行ICLRControl::GetCLRManager。
例如:
ICLRMetaHost *meta;
ICLRRuntimeInfo *info;
ICLRRuntimeHost *host;
ICLRControl *control;
ICLRAppDomainResourceMonitor *monitor;
CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (void **)&meta);
meta->GetRuntime(L"v4.0.30319", IID_CLRRuntimeInfo, (void **)&runtime);
info->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void **)&host);
host->GetCLRControl(&control);
control->GetCLRManager(IID_ICLRAppDomainResourceMonitor, (void **)&monitor);
// ... rest of CLR startup ...
unsigned long long bytes;
monitor->GetCurrentAllocated(1, &bytes);https://stackoverflow.com/questions/4066514
复制相似问题