|
// System.cpp : Implementation of CSystem
#include "stdafx.h"
#include "System.h"
#include <stdexcept>
#include "Tools\Exception.h"
#include "Windows\Handle.h"
CSystem::CSystem()
{
Update();
}
// CSystem
HRESULT CSystem::FinalConstruct()
{
return S_OK;
}
void CSystem::FinalRelease()
{
}
STDMETHODIMP CSystem::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_ISystem
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP CSystem::Update(void)
{
{
// Make sure this happens thread-safe
Windows::AutoCriticalSection lock(m_lock);
m_memoryStatus.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&m_memoryStatus);
}
return S_OK;
}
STDMETHODIMP CSystem::get_PhysicalMemoryTotal(/*[out, retval]*/ LONG *value)
{
*value = m_memoryStatus.dwTotalPhys;
return S_OK;
}
STDMETHODIMP CSystem::get_PhysicalAvailable(/*[out, retval]*/ LONG *value)
{
*value = m_memoryStatus.dwAvailPhys;
return S_OK;
}
STDMETHODIMP CSystem::get_PageFileTotal(/*[out, retval]*/ LONG *value)
{
*value = m_memoryStatus.dwTotalPageFile;
return S_OK;
}
STDMETHODIMP CSystem::get_PageFileAvailable(/*[out, retval]*/ LONG *value)
{
*value = m_memoryStatus.dwAvailPageFile;
return S_OK;
}
STDMETHODIMP CSystem::get_VirtualMemoryTotal(/*[out, retval]*/ LONG *value)
{
*value = m_memoryStatus.dwTotalVirtual;
return S_OK;
}
STDMETHODIMP CSystem::get_VirtualMemoryAvailable(/*[out, retval]*/ LONG *value)
{
*value = m_memoryStatus.dwAvailVirtual;
return S_OK;
}
STDMETHODIMP CSystem::EndProcess(/*[in]*/ LONG Pid, /*[out, retval]*/ VARIANT_BOOL *result)
{
BOOL success = FALSE;
try
{
Windows::Handle processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
success = TerminateProcess(processHandle, 0);
} catch (...)
{
}
*result = (success != FALSE) ? VARIANT_TRUE : VARIANT_FALSE;
return S_OK;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.