请教各位:为什么在使用WinExecAPI函数时,一直出现“文件格式不正确”的错误?(50分)

  • 主题发起人 主题发起人 jianhuren
  • 开始时间 开始时间
J

jianhuren

Unregistered / Unconfirmed
GUEST, unregistred user!
就是这样简单的代码<br>&nbsp; var <br>&nbsp; &nbsp; RetInteger:integer;<br>&nbsp; begin<br>&nbsp; &nbsp; RetInteger:=WinExec('D:/ECARTOON/About.swf',SW_SHOWNORMAL);<br>&nbsp; end;<br>而且在执行的机器中,SWF文件已经有关联程序。
 
WinExec('iexplore D:/ECARTOON/About.swf',SW_SHOWNORMAL);<br>&nbsp;
 
TYZhang兄,问题还是没有解决,我附上程序的代码,在请你指教一下。我查看了这个函数的使用说明,觉得我的调用没有问题,可是就是不行。<br>function TfrmMain.GetPath: string;<br>var<br>&nbsp; MyReg:TRegistry;<br>begin<br>&nbsp; MyReg:=TRegistry.Create;<br>&nbsp; MyReg.RootKey:=HKEY_LOCAL_MACHINE;<br>&nbsp; try<br>&nbsp; &nbsp; if MyReg.OpenKey('/SOFTWARE/JHSOFT/Path',false) then<br>&nbsp; &nbsp; &nbsp; Result:=MyReg.ReadString('Path')<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('键值无法打开');<br>&nbsp; &nbsp; &nbsp; &nbsp; Result:='';<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; MyReg.CloseKey;<br>&nbsp; &nbsp; MyReg.Free;<br>&nbsp; end;<br><br>end;<br><br>procedure TfrmMain.ListViewDblClick(Sender: TObject);<br>var<br>&nbsp; Path:string;<br>&nbsp; strsql:string;<br>&nbsp; tempPath:string;<br>&nbsp; RetInteger:integer;<br>begin<br>&nbsp; if ListView.SelCount=0 then<br>&nbsp; &nbsp; Exit;<br>&nbsp; Path:=GetPath();<br>&nbsp; strsql:='select Path from Common_Material where material_id=:material_id';<br>&nbsp; with frmDataModule do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; QueryPath.Active:=false;<br>&nbsp; &nbsp; &nbsp; QueryPath.SQL.Clear;<br>&nbsp; &nbsp; &nbsp; QueryPath.SQL.Add(strsql);<br>&nbsp; &nbsp; &nbsp; QueryPath.ParamByName('material_id').AsInteger:=strtoint(ListView.Selected.SubItems[2]);<br>&nbsp; &nbsp; &nbsp; if not (QueryPath.Prepared) then<br>&nbsp; &nbsp; &nbsp; &nbsp; QueryPath.Prepare;<br>&nbsp; &nbsp; &nbsp; QueryPath.Active:=true;<br>&nbsp; &nbsp; &nbsp; if not (QueryPath.eof) then<br>&nbsp; &nbsp; &nbsp; &nbsp; tempPath:=trim(QueryPath.Fields[0].Asstring)<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; tempPath:='';<br>&nbsp; &nbsp; &nbsp; path:=path+tempPath;<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; RetInteger:=Winexec(PChar(path),SW_SHOWNORMAL);<br>&nbsp; &nbsp; &nbsp; &nbsp; if RetInteger=0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('系统资源不足');<br>&nbsp; &nbsp; &nbsp; &nbsp; if RetInteger=ERROR_BAD_FORMAT then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('该文件格式无效');<br>&nbsp; &nbsp; &nbsp; &nbsp; if RetInteger=ERROR_FILE_NOT_FOUND then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('该文件没有找到');<br>&nbsp; &nbsp; &nbsp; &nbsp; if RetInteger=ERROR_PATH_NOT_FOUND then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('该文件路径没有找到');<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('发生未知错误');<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; QueryPath.Active:=false;<br>&nbsp; &nbsp; end;<br><br>end;<br>该程序的Path值可以正确读取。
 
用shellexecute把,winexec是执行可执行文件的
 
同意樓上:<br>uses shellapi;<br>shellexecute(handle,nil,PChar(path),nil,nil,sw_shownormal);
 
后退
顶部