我正在尝试创建 ICLRAppDomainResourceMonitor 的实例接口(interface),但我没有发现什么 coclass 实现它的线索。如果没有这些知识,我就无法创建 coclass 的对象实例并从 coclass 对象中检索该接口(interface)。
有人可以帮我解决这个问题吗?非常感谢。
最佳答案
在上面的代码中我们可以成功创建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();
}
但 API monitor->GetCurrentAllocation(Aid, &bytes) 返回 hr 的值为 -2146234348 即 COR_E_APPDOMAINUNLOADED
请提出您的意见。
谢谢
关于.net - 如何创建 ICLRAppDomainResourceMonitor 接口(interface)的实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4066514/