title: Install and Run Windows Service in C++
body: <p>I am working on windows services for the first time and after some effort I am now able to Install and unistall a service programatically in C++,
  I have found many tutorials which guide on how to deal with
   ServiceMain and ServiceControlHandler functions.
  Problem is that there is no tutorial which shows that first we install a service and then in the same program apply ServiceMain and ServiceControlHandler functions.</p>
  
  <p>In short I am trying to integrate both functionalities in the same code but it is not working.</p>
  
  <p>Here are some links I have followed</p>
  
  <p><a href="http://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus" rel="nofollow">http://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus</a></p>
  
  <p><a href="http://www.devx.com/cplus/Article/9857/0/page/2" rel="nofollow">http://www.devx.com/cplus/Article/9857/0/page/2</a></p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms683500(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms683500(v=vs.85).aspx</a></p>
  
  <p>my source code is almost exact copy of above examples except that before creating
  SERVICE_TABLE_ENTRY and calling StartServiceCtrlDispatcher(ServiceTable) I have called the function which Installs the service.</p>
  
  <p>The service Installs correctly but never starts running, infact ServiceMain is never called.</p>
  
  <p>Environment:
  Windows 7 64-bit
  Lnaguage C++
  Visual Studio 2008</p>