home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softwarová Záchrana 3
/
Softwarova-zachrana-3.bin
/
pserv.cpl
/
pserv-2.4.exe
/
source
/
MemoryBuffer.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2005-01-05
|
2KB
|
75 lines
#include "stdafx.h"
#include "MemoryBuffer.h"
#include "2kwrapper.h"
void MemoryBuffer::ReleaseMemory()
{
if( m_lpbDynamicMemory )
{
delete m_lpbDynamicMemory;
m_lpbDynamicMemory = NULL;
}
}
BOOL WINAPI MemoryBuffer::IQueryServiceStatusEx(LPBYTE lpbMemory, DWORD dwSize)
{
return lpfnQueryServiceStatusEx( m_hService, SC_STATUS_PROCESS_INFO, lpbMemory, dwSize, &m_dwBytesNeeded );
}
LPSERVICE_STATUS_PROCESS MemoryBuffer::QueryServiceStatusEx(SC_HANDLE hService)
{
m_hService = hService;
return LPSERVICE_STATUS_PROCESS(StandardProcess(IQueryServiceStatusEx));
}
BOOL WINAPI MemoryBuffer::IQueryServiceConfig(LPBYTE lpbMemory, DWORD dwSize)
{
return ::QueryServiceConfig(m_hService, LPQUERY_SERVICE_CONFIG(lpbMemory), dwSize, &m_dwBytesNeeded);
}
LPQUERY_SERVICE_CONFIG MemoryBuffer::QueryServiceConfig(SC_HANDLE hService)
{
m_hService = hService;
return LPQUERY_SERVICE_CONFIG(StandardProcess(IQueryServiceConfig));
}
BOOL WINAPI MemoryBuffer::IGetServiceDescription(LPBYTE lpbMemory, DWORD dwSize)
{
return lpfnQueryServiceConfig2(m_hService, SERVICE_CONFIG_DESCRIPTION, lpbMemory, dwSize, &m_dwBytesNeeded);
}
LPCTSTR MemoryBuffer::GetServiceDescription(SC_HANDLE hService)
{
if( !lpfnQueryServiceConfig2 )
return NULL;
m_hService = hService;
LPSERVICE_DESCRIPTION s = LPSERVICE_DESCRIPTION(StandardProcess(IGetServiceDescription));
return s ? s->lpDescription : NULL;
}
LPVOID MemoryBuffer::StandardProcess(MemoryBuffer::LPFNMethod func)
{
m_dwBytesNeeded = 0;
if( (this->*func)(m_bStaticMemory, sizeof(m_bStaticMemory)) )
return m_bStaticMemory;
if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
return NULL;
ReleaseMemory();
m_lpbDynamicMemory = new BYTE[m_dwBytesNeeded + 8 /* padbytes */];
if( !m_lpbDynamicMemory )
return NULL;
if( (this->*func)(m_lpbDynamicMemory, m_dwBytesNeeded) )
return m_lpbDynamicMemory;
ReleaseMemory();
return NULL;
}