2K服务进程的问题?(0分)

  • 主题发起人 主题发起人 2975097
  • 开始时间 开始时间
2

2975097

Unregistered / Unconfirmed
GUEST, unregistred user!
代码<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;<br><br>type<br>&nbsp; TXMlServer = class(TService)<br>&nbsp; &nbsp; procedure ServiceExecute(Sender: TService);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; function GetServiceController: TServiceController; override;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; XMlServer: TXMlServer;<br>&nbsp; XMlThreed:tServiceThread;<br><br>implementation<br><br>uses Unit2;<br><br>{$R *.DFM}<br><br>procedure ServiceController(CtrlCode: DWord); stdcall;<br>begin<br>&nbsp; XMlServer.Controller(CtrlCode);<br>end;<br><br>function TXMlServer.GetServiceController: TServiceController;<br>begin<br>&nbsp; Result := ServiceController;<br>end;<br><br>procedure TXMlServer.ServiceExecute(Sender: TService);<br>begin<br>&nbsp; &nbsp;NXmlServer.Create(False);<br>end;<br><br>end.<br><br>unit Unit2;<br><br>interface<br><br>uses<br>&nbsp; Classes {$IFDEF MSWINDOWS} , Windows {$ENDIF};<br><br>type<br>&nbsp; NXmlServer = class(TThread)<br>&nbsp; private<br>&nbsp; &nbsp; procedure SetName;<br>&nbsp; protected<br>&nbsp; &nbsp; procedure Execute; override;<br>&nbsp; end;<br><br>implementation<br><br>Procedure LockPC;StdCall;External 'Project2.dll';<br><br>{ Important: Methods and properties of objects in visual components can only be<br>&nbsp; used in a method called using Synchronize, for example,<br><br>&nbsp; &nbsp; &nbsp; Synchronize(UpdateCaption);<br><br>&nbsp; and UpdateCaption could look like,<br><br>&nbsp; &nbsp; procedure NXmlServer.UpdateCaption;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Form1.Caption := 'Updated in a thread';<br>&nbsp; &nbsp; end; }<br><br>{$IFDEF MSWINDOWS}<br>type<br>&nbsp; TThreadNameInfo = record<br>&nbsp; &nbsp; FType: LongWord; &nbsp; &nbsp; // must be 0x1000<br>&nbsp; &nbsp; FName: PChar; &nbsp; &nbsp; &nbsp; &nbsp;// pointer to name (in user address space)<br>&nbsp; &nbsp; FThreadID: LongWord; // thread ID (-1 indicates caller thread)<br>&nbsp; &nbsp; FFlags: LongWord; &nbsp; &nbsp;// reserved for future use, must be zero<br>&nbsp; end;<br>{$ENDIF}<br><br>{ NXmlServer }<br><br>procedure NXmlServer.SetName;<br>{$IFDEF MSWINDOWS}<br>var<br>&nbsp; ThreadNameInfo: TThreadNameInfo;<br>{$ENDIF}<br>begin<br>{$IFDEF MSWINDOWS}<br>&nbsp; ThreadNameInfo.FType := $1000;<br>&nbsp; ThreadNameInfo.FName := 'XMlServer';<br>&nbsp; ThreadNameInfo.FThreadID := $FFFFFFFF;<br>&nbsp; ThreadNameInfo.FFlags := 0;<br><br>&nbsp; try<br>&nbsp; &nbsp; RaiseException( $406D1388, 0, sizeof(ThreadNameInfo) div sizeof(LongWord), @ThreadNameInfo );<br>&nbsp; except<br>&nbsp; end;<br>{$ENDIF}<br>end;<br><br>procedure NXmlServer.Execute;<br><br>begin<br><br>&nbsp; SetName;<br>&nbsp; LockPC;<br><br>&nbsp; if Suspended then<br>&nbsp; &nbsp; &nbsp;Resume;<br><br><br><br>&nbsp; { Place thread code here }<br>end;<br><br>end.<br><br>出现错误提示为:<br>&nbsp; XXX服务不能启动,服务并未返回错误,这可能是WINDOWS内部的错误或者是程序内部的错误,如果错误继续存在,请与管理员联系。<br>
 
后退
顶部