.net - 如何创建 ICLRAppDomainResourceMonitor 接口(interface)的实例?

标签 .net clr

我正在尝试创建 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/

相关文章:

c# - sqlDecimal 到十进制 clr 存储过程无法将类型 'System.Data.SqlTypes.SqlDecimal' 的对象转换为类型 'System.IConvertible'

c# - 将不同版本的程序集加载到单独的 AppDomain 中

c# - 如何知道RichTextBox垂直Scrollbar是否达到最大值?

c# - 刷新 ListCollectionView 将 ComboBox 中所选项目的值设置为 null

c# - 在 Visual Studio 2005 中使用 Crystal Reports(C# .NET Windows 应用程序)

c# - .NET 功能和 C# 功能有什么区别? (请举例)

.net - 为什么创建一个新线程很昂贵?

c# - 一台机器上可以存在多个 CLR 版本吗?

c# - 在 C# 中验证数字签名

c# - 检测事件 RDP session