#include "stdafx.h"
#include "Windows.h"
#define SZAPPNAME "serverSample" //服务程序名
#define SZSERVICENAME "serviceSample"//标识服务的内部名
//内部变量
bool bDebugServer=false
SERVICE_STATUS ssStatus
SERVICE_STATUS_HANDLE sshStatusHandle
DWORD dwErr=0
TCHAR szErr[256]
//下面的函数由程序实现
void WINAPI Service_Main(DWORD dwArgc, LPTSTR *lpszArgv)
void WINAPI Service_Ctrl(DWORD dwCtrlCode)
void installService()
void removeService()
void debugService(int argc,char** argv)
bool ReportStatusToSCMgr(DWORD dwCurrentState,DWORD dwWin32ExitCode,DWORD dwWaitHint)
void AddToMessageLog(LPTSTR lpszMsg)
int _tmain(int argc, _TCHAR* argv[])
{
SERVICE_TABLE_ENTRY dispatchTable[]=
{
{TEXT(SZSERVICENAME),(LPSERVICE_MAIN_FUNCTION)Service_Main},
{ NULL,NULL}
}
if((argc>芦悄1)&&((*argv[1]=='-')||(argv[1]=="/")))
{
if(_stricmp("install",argv[1]+1)==0)
{
installService()
}
else if(_stricmp("remove",argv[1]+1)==0)
{
removeService()
}
else if(_stricmp("debug",argv[1]+1)==0)
{
bDebugServer=true
debugService(argc,argv)
}
else
{//如果未能和上面的如何参数匹配,则可能是服务控制管理程序来启动该程序。立即
调用
//StartServiceCtrlDispatcher 函数。
printf("%s - install to install the service \n",SZAPPNAME)
printf("%s - remove to remove the service \n",SZAPPNAME)
printf("%s - debug to debug the service \n",SZAPPNAME)
printf("\n StartServiceCtrlDispatcher being called.\扒历n"春哗搜)
printf("This may take several seconds.Please wait.\n")
if(!StartServiceCtrlDispatcher(dispatchTable))
AddToMessageLog(TEXT("StartServiceCtrlDispatcher failed."))
else
AddToMessageLog(TEXT("StartServiceCtrlDispatcher OK."))
}
exit(0)
}
return 0
}
1. 配置目标机1)亩返拷贝Remote Debugger客户端与目标程序的调试版本到目标机迅仔饥。拷贝目录C:/Program Files/Microsoft Visual Studio 8/Common7/IDE/RemoteDebugger/x86。目标程序如C:/Windows/System32/Thpsvr.exe2)执行Remote Debugger客户端程序msvsmon.exe。首先关掉Windows防火墙。运行程序后,选择[Tools]-[Options]。选择[No Authentication(native only)],并勾选[Allow any userto debug]。2. 配置主机1) 打开工程,选择调试模式。由菜单依次选择[Project] [Properties] [Configuration Properties] [Debugging]。将Debuggerto launch选为Windows Remote Debugger.2) 配置Remote Debug参数。[Remote Command] 设置为目标程戚雀序全路径,C:/Windows/System32/Thpsvr.exe。[CommandArguments] 按需要为程序设置参数。[Remote Server Name] 填入目标机的IP地址。[Connection] 设为Remote with no Authentication(native only)其它设置不需要改动。客户机和主机配置都已经完成,接下来以和本机调试相同的方法进行调试就可以了。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)