Compiling the generated program from the VS-created Windows Service project and registering it as a Windows service through the command line "service. Exe-service" can be managed through the Service manager.
Problem
The discovery service failed to start and prompted an error when booting through Service Manager
Because the program code is generated by the project template for VS, it is compiled directly into the debug version and then registered through the command line, and no code has been modified during the period.
Is it only release versions that can be started through the service Manager? The release version is then registered as a service, which is still reported to be the same error, starting with the service manager.
Because the service is more specific, you should leave a log in the Windows Event Manager, viewed by the log as
You can see that there are no exceptions in the system log.
The problem is more than that, when the debug version is registered through RegServer, the program is also stopped immediately after startup.
That being the case, you start using the artifact--step-one.
Startup Failure Reason
Once the Window service program is started, a run method is called in the WinMain method
Collapsehresult Run (_in_ int nshowcmd = sw_hide) throw ()
{
HRESULT hr = S_OK;
t* PT = static_cast<t*> (this);
hr = Pt->premessageloop (nshowcmd);
Call RunMessageLoop only if PreMessageLoop returns S_OK.
if (hr = = S_OK)
{
pt->runmessageloop ();
}
Call PostMessageLoop if PreMessageLoop returns success.
if (SUCCEEDED (HR))
{
hr = Pt->postmessageloop ();
}
Atlassert (SUCCEEDED (HR));
return hr;
}
The Run method calls the Pt->runmessageloop () method for a while loop, which prevents the WinMain method from returning, causing the program to end.
After debugging, found that execution, the Pt->premessageloop method returned S_FALSE, because the RunMessageLoop method before a judge, so this method is not executed, which causes the program to start immediately stop.
And the reason why the PreMessageLoop method returns S_FALSE is
hr = Pt->registerclassobjects (clsctx_local_server, Regcls_multipleuse | regcls_suspended);
Calls the RegisterClassObjects method, returns the S_FALSE, and the RegisterClassObjects method calls the Atlcommoduleregisterclassobjects method. is actually registering COM-related things, and because the program was compiled by the default code created by VS, no COM interface was added, so it returned S_FALSE, that is, registration failed.