PdhAddEnglishCounter/PdhAddCounter 添加cpu计数器返回-1073738824 C000 0BB8

获取cpu负载时 使用pdhaddenglishcounter 返回-1073738824  C000 0BB8  

PDH_CSTATUS_NO_OBJECT 

auto state = PdhOpenQuery(NULL, NULL, &cpuQuery);
            if (state != ERROR_SUCCESS) {
                DLOG(ERROR) << "PdhOpenQuery Failed:" << state << std::endl;
                return 0;
            }
            state = PdhAddCounter(cpuQuery, "\Processor(_Total)\% Processor Time", NULL, &cpuTotal);
            if (state != ERROR_SUCCESS)
            {
                DLOG(ERROR) << "PdhAddEnglishCounter Failed" << PdhAddEnglishCounter(cpuQuery, "\Processor(_Total)\% Processor Time", NULL, &cpuTotal) << std::endl;
                return 0;
            }

解决方法:

重置性能计数

Lodctr /r

参考:

https://helgeklein.com/blog/how-to-easily-monitor-system-performance-with-the-new-diskled-1-1/

也可能是:

计算机HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesPerfProcPerformanceDisable Performance Counters  设置成了 1

原文地址:https://www.cnblogs.com/wolbo/p/14985731.html