Detecting total RAM change in Windows
Is there a callback in Windows 开发者_如何转开发which will notify my application if the total amount of System RAM has changed?
You might be able to do this via WMI, if you can pick up _InstanceCreationEvent and _InstanceDeletionEvent on class Win32_PhysicalMemory.
There is sample code here (WMI is a bear to use in C or C++, sorry - C# would be easier). Just make the query you listen on use Win32_PhysicalMemory
rather than Win32_Process
here:
hres = pSvc->ExecNotificationQueryAsync(
_bstr_t("WQL"),
_bstr_t("SELECT * "
"FROM __InstanceCreationEvent WITHIN 1 "
"WHERE TargetInstance ISA 'Win32_Process'"),
WBEM_FLAG_SEND_STATUS,
NULL,
pStubSink);
You'd also need a second call like this for __InstanceDeletionEvent
detection.
精彩评论