title: How do I get the Service Display name in C++?
body: <p>I am trying to get the display name of the running service using c++. I was trying to use the GetServiceDisplayName function but it does not seem to be working, not sure why.</p>
  
  <pre><code>TTServiceBegin( const char *svcName, PFNSERVICE pfnService, bool *svc, PFNTERMINATE pfnTerm,
  int flags, int argc, char *argv[], DWORD dynamiteThreadWaitTime )
  {
  SC_HANDLE serviceStatusHandle;
  DWORD dwSizeNeeded = 0 ;
  TCHAR* szKeyName = NULL ;
  
  serviceStatusHandle=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE ,SC_MANAGER_ALL_ACCESS);
  
  GetServiceDisplayName(serviceStatusHandle,svcName, NULL, &amp;dwSizeNeeded);
  if(dwSizeNeeded)
  {
      szKeyName = new char[dwSizeNeeded+1];
      ZeroMemory(szKeyName,dwSizeNeeded+1);
      if(GetServiceDisplayName(serviceStatusHandle ,svcName,szKeyName,&amp;dwSizeNeeded)!=0)
      {
          MessageBox(0,szKeyName,"Got the key name",0);
      }
  
  
  }        
  </code></pre>
  
  <p>When i run this code, i can never see the value of szKeyName in my debugger and it goes into the if block for the message box but never displays the message box. Not sure why? </p>
  
  <p>Anyway to get this to work to get the display name of the service or any other/easier way to accomplish that task?</p>