PDH 无法通过 PdhAddCounter() 访问总 CPU 时间
PDH cant access total CPU time through PdhAddCounter()
我目前正在尝试为我的DirectX程序制作某种CPU使用情况概述,但似乎我无法通过PdhAddCounter()获取此信息。我的代码如下所示:
status = PdhOpenQuery(NULL, 0, &m_queryHandle);
if(status != ERROR_SUCCESS)
{
m_canReadCpu = false;
}
status = PdhAddCounter(m_queryHandle, TEXT("\Processor(_Total)\% processor time"), 0, &m_counterHandle);
if(status != ERROR_SUCCESS)
{
m_canReadCpu = false;
}
在 PdhAddCounter 调用后,我的状态是 = -1073738824,这会导致程序失败。
我使用的是 Windows 7 64 位系统,我是否必须在 64 位环境中做出一些不同的东西?感谢您的任何帮助。
请记住:PdhAddCounter是区域设置明智的。
响应 -1073738824 表示 PDH_CSTATUS_NO_OBJECT=0xC0000BB8。API 未找到该字符串。您使用的是非英语操作系统吗?
如果您需要执行与Windows XP兼容的应用程序,则需要使用如下解决方法:http://en.verysource.com/code/3604946_1/platforminfo.cpp.html。
适用于 Vista 和 Windows 7、8,...你可以改用PdhAddEnglishCounter。
您可能还想使用 GetSystemTimes kernel32 API,它将使您摆脱对 pdh.dll 的依赖。
在这里看到我的答案。
相关文章:
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 用于访问容器<T>数据成员的正确 API
- 访问者访问变体并返回不同类型时出错
- 尝试通过多个向量访问变量时,向量下标超出范围
- 无法访问嵌套类.类的使用无效
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 写入位置0x0000000C时发生访问冲突
- 我们可以访问一个不存在的联盟的成员吗
- C++从另一个类访问公共静态向量的正确方法是什么
- 如何从 CPU 访问计算着色器本地工作组的大小?
- 访问多个阵列时 CPU 缓存的作用是什么?
- 优化 CPU 流水线和缓存访问
- 为什么内存访问时间远远超过CPU缓存大小时会增加
- 在Windows中访问英特尔CPU I/O寄存器的简便方法
- PDH 无法通过 PdhAddCounter() 访问总 CPU 时间
- Direct3D 11:如何访问 CPU 端内存中的多维数据集映射人脸(ID3D11DeviceContext::Map
- 访问CPU/RAM使用情况(类似于任务管理器,但通过API!)
- 如果已知访问顺序是安全的,如何在没有互斥锁的情况下同步线程/CPU