[编程技术] 新手问一个关于c++编写windows服务程序的问题

发信人: RythmOfWind (RythmOfWind), 信区: Programming
标 题: 新手问一个关于c++编写windows服务程序的问题
发信站: 水木社区 (Sun Dec 31 16:14:45 2017), 站内



这几天想学怎么写服务程序,上网找教程没找到太好的,各位如果有什么比较好的教材
的话希望能推荐一下,谢谢!

复制了一个相关的程序,编译运行的时候报错,如附件的图片所示。搜了一下也没找到
答案,谁能教我一下?

以下是源代码:

// service_practice.cpp : Defines the entry point for the console
application.
#include "stdafx.h"
#include <afxsock.h>
#include <afx.h>
#include <time.h>
#include <Windows.h>

VOID WINAPI ServiceMain(DWORD dwArgc,LPTSTR *lpszArgv);
VOID WINAPI serviceCtrl(DWORD fdwControl);
BOOL initSocket();
int WriteToLog(char* str);
#define LOGFILE "C:\\practice.txt"
SERVICE_STATUS_HANDLE hService;
SERVICE_STATUS serviceStatus;

int hour1=10;
int minute1=0;
int hour2=24;
int minute2=0;

int main(int argc, char* argv[])
{
// printf("Hello World!\n");
//定义SERVICE_TABLE_ENTRY 结构体
SERVICE_TABLE_ENTRY serviceTable[2];
serviceTable[0].lpServiceName = "servicePractice";
serviceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;

serviceTable[1].lpServiceName = NULL;
serviceTable[1].lpServiceProc = NULL;

//connects the main thread of a service process to the service control
manager,
//which causes the thread to be the service control dispatcher thread for
the calling process.
//连接scm,让scm控制服务
//serviceTable必须要以NULL,NULL为最后一项
WriteToLog("注册服务函数开始");
StartServiceCtrlDispatcher(serviceTable);
WriteToLog("注册服务函数结束");
return 0;
}
/************************************************************************/
/*ServiceMain 服务执行函数 */
/*入参: */
/*DWORD dwArgc number of arguments */
/*LPTSTR *lpszArgv number of arguments */
/*return void */


from 水木社区 电脑技术区十大热门话题 http://ift.tt/2C3yr0u
via IFTTT

评论

此博客中的热门博文

丰田将在 2019 东京车展上展出一台超迷你的都市型电动车

[数字家庭] [原创]北京联通IPTV的完美方案

英特尔将推出更多支持 e-SIM 的 modem