delphi 2010 编译乱码问题 200
这段代码我用delphi7编译正常改成delphi2010就乱码了谁帮我改一下可以在delphi2010下可以编译谢谢functionWinExecAndWait32(F...
这段代码我用delphi7编译正常 改成delphi2010就乱码了 谁帮我改一下可以在delphi2010下可以编译 谢谢
function WinExecAndWait32(FileName: String; Visibility: Integer;
var mOutputs: string): Cardinal;
var
sa: TSecurityAttributes;
hReadPipe,hWritePipe: THandle;
ret: BOOL;
strBuff: array[0..255] of char;
lngBytesread: DWORD;
WorkDir: String;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Count: Integer;
begin
FillChar(sa, Sizeof(sa), #0);
sa.nLength := Sizeof(sa);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := nil;
ret := CreatePipe(hReadPipe, hWritePipe, @sa, 0);
WorkDir := ExtractFileDir(Application.ExeName);
FillChar(StartupInfo,Sizeof(StartupInfo), #0);
StartupInfo.cb:=Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
StartupInfo.wShowWindow:=Visibility;
StartupInfo.hStdOutput:=hWritePipe;
StartupInfo.hStdError:=hWritePipe;
if not CreateProcess(nil,
PChar(FileName), { pointer to command line string }
@sa, { pointer to process security attributes }
@sa, { pointer to thread security attributes }
True, { handle inheritance flag }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
PChar(WorkDir), { pointer to current directory name, PChar}
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) { pointer to PROCESS_INF }
then Result := INFINITE {-1} else
begin
// Form1.Hide;
// FileOpen(FileName,fmShareExclusive);
// SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
CloseHandle(hWritePipe);
mOutputs := '';
while ret do
begin
FillChar(strBuff, length(strBuff) * SizeOf(Char), 0);
ret := ReadFile(hReadPipe, strBuff, 256, lngBytesread, nil);
mOutputs := mOutputs + strBuff;
end;
Application.ProcessMessages;
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
// Form1.Close; { exit application }
CloseHandle(hReadPipe);
end;
end;
begin
//Memo1显示结果
Memo1.Lines.Clear;
//Memo2输入的 command 命令
Val := WinExecAndWait32(Memo2.Text, SW_HIDE, mOutputs);
//显示结果
Memo1.Lines.Add('******Result******'+#13#10+IntToStr(Val));
i:=1;
while i<=length(mOutputs) do
begin
if mOutputs[i]=#10 then
begin
Insert(#13,mOutputs,i);
i:=i+2;
end
else
Inc(i);
end;
Memo1.Lines.Add('******Echo******'+#13#10+mOutputs);
end; 展开
function WinExecAndWait32(FileName: String; Visibility: Integer;
var mOutputs: string): Cardinal;
var
sa: TSecurityAttributes;
hReadPipe,hWritePipe: THandle;
ret: BOOL;
strBuff: array[0..255] of char;
lngBytesread: DWORD;
WorkDir: String;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Count: Integer;
begin
FillChar(sa, Sizeof(sa), #0);
sa.nLength := Sizeof(sa);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := nil;
ret := CreatePipe(hReadPipe, hWritePipe, @sa, 0);
WorkDir := ExtractFileDir(Application.ExeName);
FillChar(StartupInfo,Sizeof(StartupInfo), #0);
StartupInfo.cb:=Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
StartupInfo.wShowWindow:=Visibility;
StartupInfo.hStdOutput:=hWritePipe;
StartupInfo.hStdError:=hWritePipe;
if not CreateProcess(nil,
PChar(FileName), { pointer to command line string }
@sa, { pointer to process security attributes }
@sa, { pointer to thread security attributes }
True, { handle inheritance flag }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
PChar(WorkDir), { pointer to current directory name, PChar}
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) { pointer to PROCESS_INF }
then Result := INFINITE {-1} else
begin
// Form1.Hide;
// FileOpen(FileName,fmShareExclusive);
// SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
CloseHandle(hWritePipe);
mOutputs := '';
while ret do
begin
FillChar(strBuff, length(strBuff) * SizeOf(Char), 0);
ret := ReadFile(hReadPipe, strBuff, 256, lngBytesread, nil);
mOutputs := mOutputs + strBuff;
end;
Application.ProcessMessages;
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
// Form1.Close; { exit application }
CloseHandle(hReadPipe);
end;
end;
begin
//Memo1显示结果
Memo1.Lines.Clear;
//Memo2输入的 command 命令
Val := WinExecAndWait32(Memo2.Text, SW_HIDE, mOutputs);
//显示结果
Memo1.Lines.Add('******Result******'+#13#10+IntToStr(Val));
i:=1;
while i<=length(mOutputs) do
begin
if mOutputs[i]=#10 then
begin
Insert(#13,mOutputs,i);
i:=i+2;
end
else
Inc(i);
end;
Memo1.Lines.Add('******Echo******'+#13#10+mOutputs);
end; 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询