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! */