📄 csdn_文档中心_c++学习笔记-后台服务程序开发模式(二).htm
字号:
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><FONT
size=5>3.控制处理程序函数<o:p></o:p></FONT></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; TEXT-INDENT: 22.5pt; mso-layout-grid-align: none; mso-char-indent-count: 2.5"><SPAN
style="COLOR: green; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P><SPAN
style="COLOR: green; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="COLOR: red; FONT-FAMILY: 新宋体; FONT-SIZE: 16pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">3.控制处理程序函数<o:p></o:p></SPAN></P></SPAN>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; TEXT-INDENT: 22.5pt; mso-layout-grid-align: none; mso-char-indent-count: 2.5"><SPAN
style="COLOR: green; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">函数<SPAN
lang=EN-US> Service_Ctrl
是服务的控制处理程序函数,由主函数线程的控制分发程序引用。在处理控制请求码时,应该在确定的时间间隔内更新服务状态检查点,避免发生服务不能响应的错误。</SPAN></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; TEXT-INDENT: 22.5pt; mso-layout-grid-align: none; mso-char-indent-count: 2.5"><SPAN
style="COLOR: green; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
lang=EN-US></SPAN></SPAN> </P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; TEXT-INDENT: 22.5pt; mso-layout-grid-align: none; mso-char-indent-count: 2.5"><SPAN
style="COLOR: green; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
lang=EN-US><o:p></o:p></SPAN></SPAN> </P>
<TABLE align=left border=0 cellPadding=0 cellSpacing=1
class=MsoNormalTable
style="BACKGROUND: black; MARGIN: auto 6.75pt; WIDTH: 100%; mso-cellspacing: .7pt; mso-table-overlap: never; mso-table-lspace: 9.0pt; mso-table-rspace: 9.0pt; mso-table-anchor-vertical: paragraph; mso-table-anchor-horizontal: margin; mso-table-left: left; mso-table-top: 7.9pt; mso-padding-alt: 7.5pt 7.5pt 7.5pt 7.5pt"
width="100%">
<TBODY>
<TR
style="HEIGHT: 32.1pt; mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD
style="BACKGROUND: #f1f1f1; BORDER-BOTTOM: #88c0b8; BORDER-LEFT: #88c0b8; BORDER-RIGHT: #88c0b8; BORDER-TOP: #88c0b8; HEIGHT: 32.1pt; PADDING-BOTTOM: 7.5pt; PADDING-LEFT: 7.5pt; PADDING-RIGHT: 7.5pt; PADDING-TOP: 7.5pt; WIDTH: 99.68%"
width="99%">
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; TEXT-INDENT: 22.5pt; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly; mso-char-indent-count: 2.5"><SPAN
lang=EN-US
style="COLOR: green; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">//控制处理程序函数<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="COLOR: blue; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">void</SPAN><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">
WINAPI Service_Ctrl(DWORD dwCtrlCode)<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">{<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 1"> </SPAN><SPAN
style="COLOR: green">//处理控制请求码<o:p></o:p></SPAN></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 1"> </SPAN><SPAN
style="COLOR: blue">switch</SPAN>(dwCtrlCode)<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 1">
</SPAN>{<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 2">
</SPAN><SPAN style="COLOR: green">//先更新服务状态为
SERVICDE_STOP_PENDING,再停止服务。<o:p></o:p></SPAN></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 1"> </SPAN><SPAN
style="COLOR: blue">case</SPAN>
SERVICE_CONTROL_STOP:<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 2">
</SPAN>ReportStatusToSCMgr(SERVICE_STOP_PENDING,NO_ERROR,500);<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 2">
</SPAN>ServiceStop();<SPAN
style="mso-tab-count: 1"> </SPAN><SPAN
style="COLOR: green">//由具体的服务程序实现<o:p></o:p></SPAN></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN
style="mso-tab-count: 2">
</SPAN><SPAN
style="COLOR: blue">return</SPAN>;<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-element: frame; mso-element-frame-hspace: 9.0pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: margin; mso-element-top: 7.9pt; mso-height-rule: exactly"><SPAN
lang=EN-US
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -