SvcMain function definition is not calling from SERVICE_TABLE_ENTRY structure in VC++

  • Thread starter Thread starter aditya satya prakash
  • Start date Start date
A

aditya satya prakash

Guest
Hi All,


I am using the SERVICE_TABLE_ENTRY structure to run the service in the calling process. Here from WinMain I am calling SvcMain function (DaliServiceStart in the below code).
When debugging from "(LPSERVICE_MAIN_FUNCTION) DaliServiceStart" the control is not going to "DaliServiceStart" function definition.

Could anyone please help me why the control is not going to "DaliServiceStart" function definition?

For your information, I upgraded the project from Visual Studio 2005 to Visual Studio 2017.

Below is the code snippet:

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

TCHAR servicePath[MAX_PATH];
GetModuleFileName(NULL, servicePath, sizeof(servicePath));

Resource resource (APC_DALI_DEFAULT_REG_PATH, APC_INSTALL_PATH);
TCHAR serviceDesc [MAX_PATH];
resource.GetString(serviceDesc, IDS_SERVICE_DESCRIPTION);

if (_tcsstr(GetCommandLine(), APC_DALI_SERVICE_INSTALL))
{
RegisterService(servicePath, APC_DALI_SERVICE_NAME, APC_DALI_SERVICE_NAME, serviceDesc);
}
else if (_tcsstr(GetCommandLine(), APC_DALI_SERVICE_UNINSTALL))
{
UnRegisterService(APC_DALI_SERVICE_NAME);
}
else if (_tcsstr(GetCommandLine(), APC_DALI_SERVICE_DEBUG))
{
worker_thread(0);
}
else
{
if (IsServiceRegistered(APC_DALI_SERVICE_NAME) == FALSE)
{
RegisterService(servicePath, APC_DALI_SERVICE_NAME, APC_DALI_SERVICE_NAME, serviceDesc);
}

// TODO: Place code here.
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{APC_DALI_SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION) DaliServiceStart},
{NULL, NULL}
};

StartServiceCtrlDispatcher( DispatchTable);
}

return 0;
}



void WINAPI DaliServiceStart (DWORD argc, LPTSTR *argv)
{
DWORD status;
DWORD specificError;

PotHttp potData(REG_POT_PATH);

DaliServiceStatus.dwServiceType = SERVICE_WIN32;
DaliServiceStatus.dwCurrentState = SERVICE_START_PENDING;

DaliServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN ; //| SERVICE_ACCEPT_POWEREVENT; //| SERVICE_ACCEPT_PAUSE_CONTINUE ;
DaliServiceStatus.dwWin32ExitCode = 0;
DaliServiceStatus.dwServiceSpecificExitCode = 0;
DaliServiceStatus.dwCheckPoint = 0;
DaliServiceStatus.dwWaitHint = 0;

DaliServiceStatusHandle = RegisterServiceCtrlHandler(APC_DALI_SERVICE_NAME, (LPHANDLER_FUNCTION)DaliServiceCtrlHandler);

if (DaliServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)
{
return;
}

// Initialization code goes here.
status = DaliServiceInitialization(argc,argv, &specificError);

// Handle error condition
if (status != NO_ERROR)
{
DaliServiceStatus.dwCurrentState = SERVICE_STOPPED;
DaliServiceStatus.dwCheckPoint = 0;
DaliServiceStatus.dwWaitHint = 0;
DaliServiceStatus.dwWin32ExitCode = status;
DaliServiceStatus.dwServiceSpecificExitCode = specificError;

SetServiceStatus (DaliServiceStatusHandle, &DaliServiceStatus);
return;
}

// Initialization complete - report running status.
DaliServiceStatus.dwCurrentState = SERVICE_RUNNING;
DaliServiceStatus.dwCheckPoint = 0;
DaliServiceStatus.dwWaitHint = 0;


if (!SetServiceStatus (DaliServiceStatusHandle, &DaliServiceStatus))
{
status = GetLastError();
}

potData.FireHeartbeat(LFC_SERVICE_STARTED);

return;
}

DaliServiceStart is declared like as shown below:

VOID WINAPI DaliServiceStart (DWORD argc, LPTSTR *argv);



Y A S Prakash

Continue reading...
 
Back
Top