录
if not CreateProcess(nil, //如果启动服务失败返回错误代码
PChar(sCommandLine),
nil,
nil,
True,
0,
nil,
PChar(sCurDirectory),
StartupInfo,
ProgramInfo.ProcessInfo) then
begin
Result := GetLastError();
end;
Sleep(dwWaitTime); //等待
end;
{停止服务,这个函数很简单,不再注释}
function StopProgram(var ProgramInfo: TProgram; dwWaitTime: LongWord): Integer;
var
dwExitCode: LongWord;
begin
Result := 0;
dwExitCode := 0;
if TerminateProcess(ProgramInfo.ProcessHandle, dwExitCode) then
begin
Result := GetLastError();
end;
Sleep(dwWaitTime);
end;
{这个是向指定程序发送数据}
procedure SendProgramMsg(DesForm: THandle; wIdent: Word; sSendMsg: string);
var
SendData: TCopyDataStruct;
nParam: Integer;
begin
nParam := MakeLong(0, wIdent);
SendData.cbData := length(sSendMsg) + 1;
GetMem(SendData.lpData, SendData.cbData);
StrCopy(SendData.lpData, PChar(sSendMsg));
SendMessage(DesForm, WM_COPYDATA, nParam, Cardinal(@SendData));
FreeMem(SendData.lpData);
end;
{初始化和反初始化}
initialization
begin
g_IniConf := Tinifile.Create(g_sConfFile);
end;
finalization
begin
g_IniConf.Free;
end;
主要是加载和保存配置过程过程重复的事情很多,可以考虑改进.
整个GShare.pas单元学习完毕,接下来可以开始主单元文件学习了.
|