用线程调用外部程序的时候,运行时报错Access Violation at address 0045E712 in module 'a.exe'.
Read of address 00000000.帮助上说;EAccessViolation is raised when an applicationDereferences a nil (Delphi) or NULL (C++) pointer.
Writes to memory reserved for executable code.
Attempts to access a memory address for which there is no virtual memory allocated to the application.我觉得是没有给程序分配内存
大家看看该怎么办
Read of address 00000000.帮助上说;EAccessViolation is raised when an applicationDereferences a nil (Delphi) or NULL (C++) pointer.
Writes to memory reserved for executable code.
Attempts to access a memory address for which there is no virtual memory allocated to the application.我觉得是没有给程序分配内存
大家看看该怎么办
解决方案 »
- 求解suiPack换肤读ini文件问题
- form 中有30个edit,当第一个edit1获得焦点时,就开始输入,并且光标一直停留在edit1上,直到edit1的内容输入完成并正确,才能使edit2得到焦点?这怎么实现??
- 测试...
- 救命啊,,,,,,,ACCESS的自定义函数在delphi的ADO控件中无法运行,怎么办?
- 为什么DELPHI做的窗口快速拖动时比VC++的尾巴明显啊?
- 急,报表中的斜线怎么划
- 我们的网站开张了,大家来看看?
- 我的问题怎么会没有人解决?
- DBGrid动态加的列不能手动输入,而且取不到值
- 如何编写一个通用函数,实现回车之后焦点自动到下一个TabOrder上去?
- 怎么样通过程序句柄得到其路径?请大家帮帮忙
- 怎样把数据库中保存的文件,在客户端不生成文件而是在内存中直接打开?
procedure TForm1.IntegratClick(Sender: TObject);
Const
Prog = 'a.exe';
ProgEnd = 'The termination of Preint.';
Var
ExitCode : Dword;
FileName,Result: String;
Restr : TStrings;begin
ExitCode := 0;
FileName := XmPath + '\' + XmName;
CommandLine := Prog + ' ' + '"' + FileName + '"' ;
Dir := XmPath;
If (Dir = '') then
begin
save1Click(Sender);
Dir :=XmPath;
End;
MemoDisplay.Clear ; Mediavar.Clear;
MediaVar.Strings[0] := CommandLine;
MediaVar.Strings[1] := Dir;
RunDosThread.Resume ;
MediaVar.Free ; Result := 'Blank testing';
Restr := TStringList.Create ;
Restr.Add(Result);
MemoDisplay.Lines := Restr;
MemoDisPlay.Lines.Append(ProgEnd);
MemoDisPlay.Lines.Append('');
Restr.Free ;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
MemoDisplay.Clear;
MemoDisplay.ReadOnly := True;
RunDosThread:=TRunDosThread.Create(True);
end;
==========================
Unit2procedure TRunDosThread.Execute;
var
Cmdl,dr:string;
ExitCd:Dword;
begin
cmdl := Form1.MediaVar[0];
dr := Form1.MediaVar[1];
ExitCd :=0;
{ Place thread code here }
If(Terminated)then exit; RunDOS(Cmdl, Dr, ExitCd);
end;procedure TRunDosThread.CheckResult (b: Boolean);
begin
if not b then
Raise Exception.Create(SysErrorMessage(GetLastError));
end;function TRunDosThread.RunDOS (const CommandLine,Dir: String; ExitCode :Dword): String;
var
HRead,HWrite:THandle;
StartInfo:TStartupInfo;
ProceInfo:TProcessInformation;
b:Boolean;
sa:TSecurityAttributes;
inS:THandleStream;
sRet:TStrings;
begin
Result := '';
FillChar(sa,sizeof(sa),0);
//设置允许继承,否则在NT和2000下无法取得输出结果
sa.nLength := sizeof(sa);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := nil;
b := CreatePipe(HRead,HWrite,@sa,0);
CheckResult(b); FillChar(StartInfo,SizeOf(StartInfo),0);
StartInfo.cb := SizeOf(StartInfo);
StartInfo.wShowWindow := SW_HIDE;
//使用指定的句柄作为标准输入输出的文件句柄,使用指定的显示方式
StartInfo.dwFlags := STARTF_USESTDHANDLES+STARTF_USESHOWWINDOW;
StartInfo.hStdError := HWrite;
StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);//HRead;
StartInfo.hStdOutput := HWrite; b := CreateProcess(Nil,//lpApplicationName: PChar
PChar(CommandLine), //lpCommandLine: PChar
nil, //lpProcessAttributes: PSecurityAttributes
nil, //lpThreadAttributes: PSecurityAttributes
True, //bInheritHandles: BOOL
CREATE_NEW_CONSOLE,
nil,
PChar(Dir),
StartInfo,
ProceInfo ); CheckResult(b);
WaitForSingleObject(ProceInfo.hProcess,INFINITE);
GetExitCodeProcess(ProceInfo.hProcess,ExitCode);
// GetExitCodeProcess(ProceInfo.hProcess,ExitCode);
inS := THandleStream.Create(HRead);
if inS.Size>0 then
begin
sRet := TStringList.Create;
sRet.LoadFromStream(inS);
Result := sRet.Text;
sRet.Free;
end;
inS.Free;
CloseHandle(HRead);
CloseHandle(HWrite);
end;
但是别人推荐使用
http://community.csdn.net/Expert/topic/4502/4502833.xml?temp=.4399378