添加一个利用Svchost启动的DLL共享服务,在注册表已成功添加,但在服务界面就是启动不起来,会报错126:找不到指定模块。
查了很多说该错误是因为dll文件有问题,有没有大佬帮忙看一下dll文件错在哪?
dllmain.cpp:
service.h:
#pragma once
#include "stdafx.h"
#ifdef __cplusplus
extern "C"
{
#endif
__declspec(dllexport) VOID WINAPI ServiceMain(DWORD dwArgc, LPCTSTR* lpszArgv);
#ifdef __cplusplus
}
#endif
service.cpp:
#include "service.h"
#include "stdafx.h"
SERVICE_STATUS_HANDLE g_service_status_handle = NULL;
SERVICE_STATUS g_service_status =
{
SERVICE_WIN32_SHARE_PROCESS,
SERVICE_START_PENDING,
SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_PAUSE_CONTINUE
};
DWORD WINAPI ServiceHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
{
switch (dwControl)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
g_service_status.dwCurrentState = SERVICE_STOPPED;
break;
case SERVICE_CONTROL_PAUSE:
g_service_status.dwCurrentState = SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE:
g_service_status.dwCurrentState = SERVICE_RUNNING;
break;
case SERVICE_CONTROL_INTERROGATE:
break;
default:
break;
};
SetServiceStatus(g_service_status_handle, &g_service_status);
return NO_ERROR;
}
extern "C" __declspec(dllexport) VOID WINAPI ServiceMain(DWORD dwArgc, LPCTSTR* lpszArgv)
{
g_service_status_handle = RegisterServiceCtrlHandlerEx(TEXT("Svchost Service"), ServiceHandler, NULL);
if (!g_service_status_handle)
{
return;
}
g_service_status.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(g_service_status_handle, &g_service_status);
while (TRUE)
{
Sleep(1000);
OutputDebugString(TEXT("Hello Topsec In Svchost"));
}
return;
};