tmp

http://bbs.sjtu.edu.cn/bbscon,board,GNULinux,file,M.1211644138.A.html

http://www.oschina.net/news/23047/piggydb-5-1     piggydb个人知识库

http://www.cnblogs.com/chengmin/archive/2010/10/24/1859839.html IPV6

http://blog.csdn.net/masikkk/article/details/5722258 基于ipv6的socket通信(TCP)

http://blog.csdn.net/niying/article/details/1054180  将程序注册为服务


在SCM(服务管理器)中注册
1.在main中添写一个SERVICE_TABLE_ENTRY 结构,两个成员,一个是服务名,一个是服务函数(ServiceMain)
  使用StartServiceCtrlDispatcher注册上述结构体
2.SCM会在打开服务时调用ServiceMain(),主要是用来调用RegisterServiceCtrlHandler()为服务注册一个控制函数(Handler),功能是与SCM通信进行服务管理。
3.服务功能实现函数由ServiceMain()启动一个专用线程来完成
4.具有以上模块的程序才能注册为服务,使用OpenSCManager()和CreateService()

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "ServiceMain.h"
#pragma comment(lib, "Advapi32.lib")


char *SERVICE_NAME ="MyService";
HANDLE threadHandle =NULL;
SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;
void ControlHandler(DWORD request);
int InitService();
int WriteToLog(char* str);


VOID WINAPI ServiceCtrlHandler( DWORD controlCode)
{
//SERVICE_STATUSserviceStatus;
//serviceStatus.dwCheckPoint=1;
//serviceStatus.dwControlsAccepted=0;
//serviceStatus.dwServiceSpecificExitCode=0;
//serviceStatus.dwWaitHint=0;
//serviceStatus.dwWin32ExitCode=NO_ERROR;
//serviceStatus.dwServiceType=SERVICE_WIN32_OWN_PROCESS;
//serviceStatus.dwCurrentState=SERVICE_RUNNING;

ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(hStatus,&ServiceStatus);
}


VOID WINAPI MyServiceMain(DWORD argc,LPTSTR *argv)
{
int error;
hStatus = 
RegisterServiceCtrlHandler( SERVICE_NAME,
(LPHANDLER_FUNCTION)ServiceCtrlHandler);
error = InitService();
if (error)
{
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = -1;
SetServiceStatus(hStatus,&ServiceStatus);
return;
}
}


int InitService()
{
int result;
result = WriteToLog("Monitoring started.");
return result;
}


int WriteToLog(char* str)
{
FILE* log;
log = fopen(LOGFILE, "a+");
if (log == NULL)
return -1;


fprintf(log, "%s\n", str);
fclose(log);
return 0;
}


void main()
{
SERVICE_TABLE_ENTRY ServiceTable[2];
ServiceTable[0].lpServiceName = SERVICE_NAME;
ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)MyServiceMain;
ServiceTable[1].lpServiceName = NULL;
ServiceTable[1].lpServiceProc = NULL;
StartServiceCtrlDispatcher(ServiceTable);
}

你可能感兴趣的:(socket,function,File,service,table,winapi)