c - 检测 Windows 中的总 RAM 变化

标签 c windows winapi

如果系统 RAM 总量发生变化,Windows 中是否有回调通知我的应用程序?

最佳答案

如果您可以获取 _InstanceCreationEvent,您也许可以通过 WMI 执行此操作和 _InstanceDeletionEvent上课Win32_PhysicalMemory .

有示例代码here (WMI 不适合在 C 或 C++ 中使用,抱歉 - C# 会更容易)。只需在此处使用 Win32_PhysicalMemory 而不是 Win32_Process 使您监听的查询:

hres = pSvc->ExecNotificationQueryAsync(
    _bstr_t("WQL"), 
    _bstr_t("SELECT * " 
        "FROM __InstanceCreationEvent WITHIN 1 "
        "WHERE TargetInstance ISA 'Win32_Process'"), 
    WBEM_FLAG_SEND_STATUS, 
    NULL, 
    pStubSink);

您还需要像这样进行第二次调用以检测 __InstanceDeletionEvent

关于c - 检测 Windows 中的总 RAM 变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4150426/

相关文章:

c - 除了混淆矩阵还有哪些其他形式的评估?

c - Pthread 服务器编程 : how to release a thread which is blocked on a recv call to handle a request from another thread

c - <string.h> 和 <strings.h> 的区别

c - 下面的c定义的语法是什么?

c++ - MFC分配大内存

linux - 当我包含 git bash 命令行时,pwd 在 Windows 中不起作用?

windows - 如何将批处理文件作为 Tortoise SVN Hook 执行

java - 如何防止 JNI 覆盖 GetLastError()

windows - 如何在控制台中检测当前是否启用 Windows 10 缓冲区包装模式

winapi - 如何确定用于制作Windows应用程序的开发工具?