How to create an instance of ICLRAppDomainResourceMonitor interface?
I am trying to create an instance of ICLRAppDomainResourceMonitor interface, but I found no clue of what coclass implements it. Without that knowledge, I cannot create an object instance of 开发者_JS百科the coclass and retrieve that interface from the coclass object.
Could anyone help me on this? Many thanks.
In above code we can create instance of ICLRAppDomainResourceMonitor successfully.
Actually I am trying to fetch values of attributes of each AppDomain of each .NET 4.0 processes running on the same system.
I tried following code to fetch data of 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();
}
but API monitor->GetCurrentAllocated(Aid, &bytes) return value of hr as -2146234348 ie COR_E_APPDOMAINUNLOADED
Please provide your comments.
Thanks,
Once you have a ICLRControl, generated from ICLRRuntimeHost::GetCLRControl, execute ICLRControl::GetCLRManager using IID_ICLRAppDomainResourceMonitor for the desired interface.
e.g.
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);
Edit: Note, you have to use the CLR v4.0 for the to work. Using the 4.0 metahost and 2.0 runtime isn't enough.
精彩评论