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