он работает, если я позвоню на этапе установки:
Код: Выделить всё
int wmain(int argc, wchar_t *argv[])
{
wchar_t dbg[256];
if ((argc > 1) && ((*argv[1] == L'-' || (*argv[1] == L'/'))))
{
if (_wcsicmp(L"install", argv[1] + 1) == 0)
{
// Install the service when the command is
// "-install" or "/install".
InstallService(
SERVICE_NAME, // Name of service
SERVICE_DISPLAY_NAME, // Name to display
SERVICE_START_TYPE, // Service start type
SERVICE_DEPENDENCIES, // Dependencies
SERVICE_ACCOUNT, // Service running account
SERVICE_PASSWORD // Password of the account
);
}
else if (_wcsicmp(L"remove", argv[1] + 1) == 0)
{
// Uninstall the service when the command is
// "-remove" or "/remove".
UninstallService(SERVICE_NAME);
}
}
else
{
wprintf(L"Parameters:\n");
wprintf(L" -install to install the service.\n");
wprintf(L" -remove to remove the service.\n");
CPictureRecorderService service(SERVICE_NAME, TRUE,TRUE,TRUE);
if (!CServiceBase::Run(service))
{
swprintf_s(dbg,256, L"Service failed to run w/err 0x%08lx\n", GetLastError());
OutputDebugStringW(dbg);
}
else
{
swprintf_s(dbg, 256, L"%s : Service Installed OK\n", __FUNCTIONW__);
OutputDebugStringW(dbg);
}
}
return 0;
}
< /code>
, пока я позвоню в метод начала: < /p>
void CServiceBase::Start(DWORD dwArgc, PWSTR *pszArgv)
{
int err = 0;
try
{
char dbgInfo[512] = { 0 };
// Tell SCM that the service is starting.
SetServiceStatus(SERVICE_START_PENDING);
swprintf_s(dbg, 1024, L"%s : Called start", __FUNCTIONW__);
WriteEventLogEntry(dbg, EVENTLOG_INFORMATION_TYPE);
OutputdebugStringW(dbg);
// Tell SCM that the service is started.
SetServiceStatus(SERVICE_RUNNING);
swprintf_s(dbg, 1024, L"%s : Service running", __FUNCTIONW__);
WriteEventLogEntry(dbg, EVENTLOG_INFORMATION_TYPE);
OutputdebugStringW(dbg);
}
catch (std::exception exc)
{
// Log the error.
swprintf_s(dbg, 1024, L"%s : Exception raised starting service (%S)", __FUNCTIONW__, exc.what());
WriteEventLogEntry(dbg, EVENTLOG_ERROR_TYPE);
OutputdebugStringW(dbg);
// Set the service status to be stopped.
SetServiceStatus(SERVICE_STOPPED);
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... s-services