No COM interface Why Windows Service failed to start and the solution

Source: Internet
Author: User
Tags command line log system log

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.