您的位置:逆风者 VC++ 正文
 添加时间:2007-09-01 原文发表:2007-08-31 人气:460 来源:vckbase.com

本文章共9505字,分7页,当前第6页,快速翻页:
 
ControlService 所能处理的用户消息必须在 128 到 255 这个范围。我定义了一个常量 SERVICE_CONTROL_USER,128 作为基值。范围内的用户消息被发送到 CNTService:: OnUserControl,在例子服务中,处理此消息的细节如下:
逆@风@者
BOOL CMyService::OnUserControl(DWORD dwOpcode)

{

    switch (dwOpcode) {

    case SERVICE_CONTROL_USER   0:



        // Save the current status in the registry.

        SaveStatus();

        return TRUE;



    default:

        break;

    }

    return FALSE;   // say not handled

}		
SaveStatus 是一个局部函数,用来在注册表中存储服务状态。

调试 Win32 服务

  main 函数中包含一个对 DebugBreak 的调用,当服务第一次被启动时,它会激活系统调试器。你可以监控来自调试器命令窗口中的服务调试信息。你可以在服务中用 CNTService::DebugMsg 来报告调试期间感兴趣的事件。
  为了调试服务代码,你需要按照 Platform SDK 文档中的要求安装 系统调试器(WinDbg)。你也可以用 Visual Studio 自带的调试器调试 Win32 服务。
  有一点很重要,那就是 当它被服务管理器控制时,你不能终止服务和单步执行,因为服务管理器会让服务请求 超时并终止服务线程。所以你只能让服务吐出消息,跟踪其过程并在调试器窗口查看它们。
  当服务启动后(例如,从控制面板的“服务”中),调试器将在服务线程的挂起后启动。你需要通过单击“Go”按钮或按 F5 让继续运行。然后在调试器中观察服务的运行过程。

下面是启动和终止服务的调试输出例子:
Module Load: WinDebug/NTService.exe (symbol loading deferred)

Thread Create: Process=0, Thread=0

Module Load: C:\NT351\system32\NTDLL.DLL (symbol loading deferred)

Module Load: C:\NT351\system32\KERNEL32.DLL (symbol loading deferred)

Module Load: C:\NT351\system32\ADVAPI32.DLL (symbol loading deferred)

Module Load: C:\NT351\system32\RPCRT4.DLL (symbol loading deferred)

Thread Create: Process=0, Thread=1

*** WARNING: symbols checksum is wrong 0x0005830f 0x0005224f for C:\NT351\symbols\dll\NTDLL.DBG

Module Load: C:\NT351\symbols\dll\NTDLL.DBG (symbols loaded)

Thread Terminate: Process=0, Thread=1, Exit Code=0

Hard coded breakpoint hit

Hard coded breakpoint hit

[](130): CNTService::CNTService()

Module Load: C:\NT351\SYSTEM32\RPCLTC1.DLL (symbol loading deferred)

[NT Service Demonstration](130): Calling StartServiceCtrlDispatcher()

Thread Create: Process=0, Thread=2

[NT Service Demonstration](174): Entering CNTService::ServiceMain()

[NT Service Demonstration](174): Entering CNTService::Initialize()

[NT Service Demonstration](174): CNTService::SetStatus(3026680, 2)

[NT Service Demonstration](174): Sleeping...

[NT Service Demonstration](174): CNTService::SetStatus(3026680, 4)

[NT Service Demonstration](174): Entering CNTService::Run()

[NT Service Demonstration](174): Sleeping...

[NT Service Demonstration](174): Sleeping...

[NT Service Demonstration](174): Sleeping...

[NT Service Demonstration](130): CNTService::Handler(1)

[NT Service Demonstration](130): Entering CNTService::Stop()

[NT Service Demonstration](130): CNTService::SetStatus(3026680, 3)

[NT Service Demonstration](130): Leaving CNTService::Stop()

[NT Service Demonstration](130): Updating status (3026680, 3)

[NT Service Demonstration](174): Leaving CNTService::Run()

[NT Service Demonstration](174): Leaving CNTService::Initialize()

[NT Service Demonstration](174): Leaving CNTService::ServiceMain()

[NT Service Demonstration](174): CNTService::SetStatus(3026680, 1)

Thread Terminate: Process=0, Thread=2, Exit Code=0

[NT Service Demonstration](130): Returned from StartServiceCtrlDispatcher()

Module Unload: WinDebug/NTService.exe

Module Unload: C:\NT351\system32\NTDLL.DLL

Module Unload: C:\NT351\system32\KERNEL32.DLL

Module Unload: C:\NT351\system32\ADVAPI32.DLL

Module Unload: C:\NT351\system32\RPCRT4.DLL

Module Unload: C:\NT351\SYSTEM32\RPCLTC1.DLL

Thread Terminate: Process=0, Thread=0, Exit Code=0

Process Terminate: Process=0, Exit Code=0

>
 
本文章更多内容<<上一页 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 下一页>>
相关文章

DataGrid的客户端分页
真正的全动态报表:RDLC ReportViewer
COM 组件设计与应用(十六)——连接点(vc.
如何实现Office式样的扁平组合框
在EVC3.0中使用数据库
浅谈PDFlib中文输出(二)如何在PDFlib中使
Brew 后台应用开发
VC中调用EXECL模板生成报表
在Visual C 中定制AppWizard (一)
连接 COM 与 .NET 的桥梁(一)——预备知识
层叠式窗体控件指南
基于 SSL 的 ASP.NET Web 应用测试自动化
Windows SDK笔记(七):创建MDI窗口
KVIP考勤系统
一个生成公章图片的简易工具

相关评论


本文章所属分类:首页 VC++

  热门关键字: