如何创建 ICLRAppDomainResourceMonitor 接口的实例?

发布于 2024-09-29 15:52:07 字数 230 浏览 0 评论 0原文

我正在尝试创建 ICLRAppDomainResourceMonitor 接口的实例,但我发现没有coclass 实现它的线索。如果没有这些知识,我就无法创建 coclass 的对象实例并从 coclass 对象中检索该接口。

有人能帮我解决这个问题吗?非常感谢。

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 the coclass and retrieve that interface from the coclass object.

Could anyone help me on this? Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捶死心动 2024-10-06 15:52: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();

}

但 API monitor->GetCurrentAllocation(Aid, &bytes) 将 hr 的返回值设为 -2146234348 ie COR_E_APPDOMAINUNLOADED

请提供您的意见。

谢谢,

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,

白芷 2024-10-06 15:52:07

一旦您拥有从 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);

编辑:注意,您必须使用 CLR v4.0 才能工作。使用 4.0 元主机和 2.0 运行时是不够的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文