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 >
C/C++ Source or Header  |  2005-01-05  |  2KB  |  75 lines

  1. #include "stdafx.h"
  2. #include "MemoryBuffer.h"
  3. #include "2kwrapper.h"
  4.  
  5. void MemoryBuffer::ReleaseMemory()
  6. {
  7.     if( m_lpbDynamicMemory )
  8.     {
  9.         delete m_lpbDynamicMemory;
  10.         m_lpbDynamicMemory = NULL;
  11.     }
  12. }
  13.  
  14. BOOL WINAPI MemoryBuffer::IQueryServiceStatusEx(LPBYTE lpbMemory, DWORD dwSize)
  15. {
  16.     return lpfnQueryServiceStatusEx( m_hService, SC_STATUS_PROCESS_INFO, lpbMemory, dwSize, &m_dwBytesNeeded );
  17. }
  18.  
  19. LPSERVICE_STATUS_PROCESS MemoryBuffer::QueryServiceStatusEx(SC_HANDLE hService)
  20. {
  21.     m_hService = hService;
  22.  
  23.     return LPSERVICE_STATUS_PROCESS(StandardProcess(IQueryServiceStatusEx)); 
  24. }
  25.  
  26. BOOL WINAPI MemoryBuffer::IQueryServiceConfig(LPBYTE lpbMemory, DWORD dwSize)
  27. {
  28.     return ::QueryServiceConfig(m_hService, LPQUERY_SERVICE_CONFIG(lpbMemory), dwSize, &m_dwBytesNeeded);
  29. }
  30.  
  31. LPQUERY_SERVICE_CONFIG MemoryBuffer::QueryServiceConfig(SC_HANDLE hService)
  32. {
  33.     m_hService = hService;
  34.     return LPQUERY_SERVICE_CONFIG(StandardProcess(IQueryServiceConfig));
  35. }
  36.  
  37. BOOL WINAPI MemoryBuffer::IGetServiceDescription(LPBYTE lpbMemory, DWORD dwSize)
  38. {
  39.     return lpfnQueryServiceConfig2(m_hService, SERVICE_CONFIG_DESCRIPTION, lpbMemory, dwSize, &m_dwBytesNeeded);
  40. }
  41.  
  42. LPCTSTR MemoryBuffer::GetServiceDescription(SC_HANDLE hService)
  43. {
  44.     if( !lpfnQueryServiceConfig2 )
  45.         return NULL;
  46.  
  47.     m_hService = hService;
  48.  
  49.     LPSERVICE_DESCRIPTION s = LPSERVICE_DESCRIPTION(StandardProcess(IGetServiceDescription));
  50.     return s ? s->lpDescription : NULL;
  51. }
  52.  
  53. LPVOID MemoryBuffer::StandardProcess(MemoryBuffer::LPFNMethod func)
  54. {
  55.     m_dwBytesNeeded = 0;
  56.     if( (this->*func)(m_bStaticMemory, sizeof(m_bStaticMemory)) )
  57.         return m_bStaticMemory;
  58.     
  59.     if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
  60.         return NULL;
  61.  
  62.     ReleaseMemory();
  63.  
  64.     m_lpbDynamicMemory = new BYTE[m_dwBytesNeeded + 8 /* padbytes */];
  65.     if( !m_lpbDynamicMemory )
  66.         return NULL;
  67.  
  68.     if( (this->*func)(m_lpbDynamicMemory, m_dwBytesNeeded) )
  69.         return m_lpbDynamicMemory;
  70.  
  71.     ReleaseMemory();
  72.     return NULL;
  73. }
  74.  
  75.