Changeset 8f167e8 in nscp


Ignore:
Timestamp:
06/14/08 18:06:38 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
dff5db9
Parents:
eb30340
Message:

proper versions (memleak fix)

Location:
include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/EnumNtSrv.cpp

    r978bd31 r8f167e8  
    136136// dwType = bit OR of SERVICE_WIN32, SERVICE_DRIVER 
    137137// dwState = bit OR of SERVICE_ACTIVE, SERVICE_INACTIVE 
    138 TNtServiceInfo *TNtServiceInfo::EnumServices(DWORD dwType, DWORD dwState, DWORD *pdwCount) 
    139 { 
    140   ASSERT(pdwCount != NULL); 
     138TNtServiceInfoList TNtServiceInfo::EnumServices(DWORD dwType, DWORD dwState) 
     139{ 
     140  TNtServiceInfoList ret; 
    141141  // Maybe check if dwType and dwState have at least one constant specified 
    142   *pdwCount = 0; 
    143   TNtServiceInfo *info = NULL; 
    144142  SC_HANDLE scman = ::OpenSCManager(NULL,NULL,SC_MANAGER_ENUMERATE_SERVICE); 
    145143  if (scman) { 
     
    154152      ::EnumServicesStatus(scman,dwType,dwState,lpservice,bytes, 
    155153        &bytesNeeded,&servicesReturned,&resumeHandle); 
    156       *pdwCount = servicesReturned;    // Not a chance that 0 services is returned 
    157       info = new TNtServiceInfo [servicesReturned]; 
    158154      TCHAR Buffer[1024];       // Should be enough for service info 
    159155      QUERY_SERVICE_CONFIG *lpqch = (QUERY_SERVICE_CONFIG*)Buffer; 
    160156      for (DWORD ndx = 0; ndx < servicesReturned; ndx++) { 
    161         info[ndx].m_strServiceName = lpservice[ndx].lpServiceName; 
    162         info[ndx].m_strDisplayName = lpservice[ndx].lpDisplayName; 
    163         info[ndx].m_dwServiceType = lpservice[ndx].ServiceStatus.dwServiceType; 
    164         info[ndx].m_dwCurrentState = lpservice[ndx].ServiceStatus.dwCurrentState; 
     157        TNtServiceInfo info; 
     158        info.m_strServiceName = lpservice[ndx].lpServiceName; 
     159        info.m_strDisplayName = lpservice[ndx].lpDisplayName; 
     160        info.m_dwServiceType = lpservice[ndx].ServiceStatus.dwServiceType; 
     161        info.m_dwCurrentState = lpservice[ndx].ServiceStatus.dwCurrentState; 
    165162        SC_HANDLE sh = ::OpenService(scman,lpservice[ndx].lpServiceName,SERVICE_QUERY_CONFIG); 
    166163        if (::QueryServiceConfig(sh,lpqch,sizeof(Buffer),&bytesNeeded)) { 
    167           info[ndx].m_strBinaryPath = lpqch->lpBinaryPathName; 
    168           info[ndx].m_dwStartType = lpqch->dwStartType; 
    169           info[ndx].m_dwErrorControl = lpqch->dwErrorControl; 
     164          info.m_strBinaryPath = lpqch->lpBinaryPathName; 
     165          info.m_dwStartType = lpqch->dwStartType; 
     166          info.m_dwErrorControl = lpqch->dwErrorControl; 
    170167        } 
    171168        ::CloseServiceHandle(sh); 
     169        ret.push_back(info); 
    172170      } 
    173171      delete [] lpservice; 
     
    175173    ::CloseServiceHandle(scman); 
    176174  } 
    177   return info; 
    178 } 
     175  return ret; 
     176} 
     177 
    179178 
    180179#define SC_BUF_LEN 4096 
     
    193192    if (GetServiceKeyName(scman, name.c_str(), buf, &bufLen) == 0) { 
    194193      ::CloseServiceHandle(scman); 
     194      delete [] buf; 
    195195      throw NTServiceException(name, _T("GetServiceKeyName: Could not translate service name"), GetLastError()); 
    196196    } 
     
    204204    */ 
    205205    sh = ::OpenService(scman,buf,SERVICE_QUERY_STATUS); 
     206    delete [] buf; 
    206207    if (sh == NULL) { 
    207208      ::CloseServiceHandle(scman); 
     
    224225} 
    225226 
    226  
     227/* 
    227228// Enumerate services on this machine and return an STL list of service objects  
    228229// dwType = bit OR of SERVICE_WIN32, SERVICE_DRIVER 
     
    239240  delete [] pSrvList; 
    240241} 
    241  
     242*/ 
    242243/*############################################################################# 
    243244# End of file ENUMNTSRV.CPP 
  • include/EnumNtSrv.h

    r99e4d8f r8f167e8  
    7070  std::wstring GetCurrentState(void); 
    7171 
    72   static TNtServiceInfo *EnumServices(DWORD dwType, DWORD dwState, DWORD *pdwCount); 
    73   static void EnumServices(DWORD dwType, DWORD dwState, TNtServiceInfoList *pList); 
     72  static TNtServiceInfoList EnumServices(DWORD dwType, DWORD dwState); 
     73  //static void EnumServices(DWORD dwType, DWORD dwState, TNtServiceInfoList *pList); 
    7474  static TNtServiceInfo GetService(std::wstring); 
    7575}; 
Note: See TracChangeset for help on using the changeset viewer.