title: Windows service doesn't enter _tmain on startup
body: <p>I am writing a service based on the tutorial at the following page:
  <a href="https://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus" rel="nofollow noreferrer">https://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus</a></p>
  
  <p>I can successfully create the service using:</p>
  
  <pre><code>sc create service_name binPath=&lt;path_name&gt;
  </code></pre>
  
  <p>When I attempt to start the service, I get the following error:</p>
  
  <pre><code>sc start service_name
  [SC] StartService FAILED 1053:
  The service did not respond to the start or control request in a timely fashion.
  </code></pre>
  
  <p>Here is my main():</p>
  
  <pre><code>int main (int argc, char *argv[])
  {
      OutputDebugString("service_name: entered main");
      SERVICE_TABLE_ENTRY ServiceTable[] = 
      {
          {SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
          {NULL, NULL}
      };
  
      if (StartServiceCtrlDispatcher (ServiceTable) == FALSE)
      {
          return GetLastError();
      }
  
      return 0;
  }
  </code></pre>
  
  <p><strong>EDIT</strong>: I switched from log files to OutputDebugString()/DebugView</p>
  
  <p>I ran DebugView, and I never receive "entered main". However, if I replace the contents of my worker thread with a return statement, I do start up successfully, and I receive the debug message, so I know that DebugView is working correctly.</p>
  
  <p>Here is where I create my worker thread:</p>
  
  <pre><code>// Start a thread that will perform the main task of the service
  HANDLE hThread = CreateThread (NULL, 0, ServiceWorkerThread, NULL, 0, NULL);
  if (hThread) {
      // Wait until our worker thread exits, so we can set state to SERVICE_STOPPED and return needs to stop
      WaitForSingleObject (hThread, INFINITE);
  } else {
      OutputDebugString("service_name: ServiceMain: CreateThread returned NULL");
  }
  </code></pre>
  
  <p>It seems like my worker thread is responsible for the startup error, but why wouldn't I get debug messages at the top of main()?</p>