📄 csdn_文档中心_c++学习笔记-后台服务程序开发模式(四).htm
字号:
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">else<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: 3">
</SPAN>_tprintf(TEXT("OpenService failed - %s
\n"),GetLastError());<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>CloseServiceHandle(schSCManager);<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: 1"> </SPAN><SPAN
style="COLOR: blue">else<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>_tprintf(TEXT("OpenSCManager failed - %s
\n"),GetLastError());<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"><o:p> </o:p></SPAN></P></TD></TR></TBODY></TABLE>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> <FONT size=2>在编译程序的时候,我们会发觉<SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ServiceStop();<SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ServicePause();<SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">ServiceContinue();等三个函数没有具体实现,这对于理解此文的人来说应该不难编写,在此我可以给点文档内的参考:声明
SetTheServiceStatus()函数,</SPAN></SPAN></SPAN></FONT></P>
<P><SPAN lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">//
<BR> // SetTheServiceStatus - This
just wraps up SetServiceStatus.<BR> // <BR>
void SetTheServiceStatus(DWORD dwCurrentState, DWORD
dwWin32ExitCode,<BR>
DWORD dwCheckPoint, DWORD dwWaitHint)<BR>
{<BR> SERVICE_STATUS ss; //
Current status of the service.<BR><BR>
// <BR> // Disable control requests
until the service is started.<BR> //
<BR> if (dwCurrentState ==
SERVICE_START_PENDING)<BR>
ss.dwControlsAccepted = 0;<BR>
else<BR>
ss.dwControlsAccepted
=<BR>
SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN;<BR>
// Other flags include
SERVICE_ACCEPT_PAUSE_CONTINUE<BR>
// and
SERVICE_ACCEPT_SHUTDOWN.<BR><BR> //
Initialize ss structure.<BR>
ss.dwServiceType
= SERVICE_WIN32_OWN_PROCESS;<BR>
ss.dwServiceSpecificExitCode = 0;<BR>
ss.dwCurrentState
= dwCurrentState;<BR>
ss.dwWin32ExitCode
= dwWin32ExitCode;<BR>
ss.dwCheckPoint
= dwCheckPoint;<BR>
ss.dwWaitHint
= dwWaitHint;<BR><BR> // Send status
of the service to the Service
Controller.<BR> if
(!SetServiceStatus(ssh,
&ss))<BR>
ErrorStopService(TEXT("SetServiceStatus"));<BR>
}</SPAN></SPAN></SPAN></P>
<P><SPAN lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">
然后用如下的方式来调用函数来实现源程序中缺少的功能 : </SPAN></SPAN></SPAN></P>
<P><SPAN lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -