0
votes
void WINAPI ServiceMain(DWORD argc, char* argv)
{
    m_ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
    m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
    m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
    m_ServiceStatus.dwWin32ExitCode = 0;
    m_ServiceStatus.dwServiceSpecificExitCode = 0;
    m_ServiceStatus.dwCheckPoint = 0;
    m_ServiceStatus.dwWaitHint = 0;

    m_ServiceStatusHandle = ::RegisterServiceCtrlHandler( g_szServerName, ServiceCtrlHandler );

    if( m_ServiceStatusHandle )
    {
        m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
        m_ServiceStatus.dwCheckPoint = 0;
        m_ServiceStatus.dwWaitHint = 0;
        SetServiceStatus( m_ServiceStatusHandle, &m_ServiceStatus );

        //TODO
        HRESULT hr = StartFSServer(theApp.m_hInstance, &CLSID_WNCOPC);
        hr = RegisterServer();

        g_pCallBackObj = new CWSCallback();
        SetCallbackObject(g_pCallBackObj);

        CKernelService::GetInstance()->Run();
    }
}

/* I want to make a OPC Server as a windows service use factorysoft opc server toolkit. The above is my ServiceMain function. The instruction document says "The interface allows this DLL to be added to existing applications as well as new ones. FSServer also hides OPC details so that any kind of application can use it, including windows SDK, MFC, console applications, and services. ", so I think I can use it in windows service. But when I run the service and use OPC Client to connect the OPC Server, it failed with(HR = 80080005). I found that even the service is running and StartFSServer excute succeed, the system still try to run a new instance of OPC Server. Thanks! */

1

1 Answers

0
votes

It looks like that you have turned your OPC server into a Windows service, but you may still be registering it as a Local Server, not a Service. The COM registry entries for the Service need to be different. One way to figure this out is to look how other COM objects that reside in Windows Services are represented in registry. The other way is e.g. to create a sample COM Server using ATL, with Visual C++ Wizard, then run it with /Service on a command line, and see what it does to the registry.