其实很简单~~~~~~~ShellExecute()(20分)

  • 主题发起人 主题发起人 beachboy
  • 开始时间 开始时间
B

beachboy

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要在程序中调用一个可执行文件,比如jps.exe<br>jps.exe在DOS使用时参数如下:jps.exe filename &nbsp;-o &lt;output Directory&gt; -p -g<br>我在Win下使用API调用时这样写:<br>var<br>filename,path,par:string;<br>begin<br>&nbsp; filename:=Mainfrm.FilenameEdt.FileName;//获得文件名<br>&nbsp; Path:=ExtractFileDir(filename); //获得输出的文件夹<br>&nbsp; Par:=filename+#32+'-o'+#32+path; //可执行文件操作参数<br>&nbsp; ShellExecute(Application.MainForm.Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'open',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PChar('jps.exe'),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PChar(par),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SW_Hide<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); <br>end;<br>但是执行结果就是不行;<br>但是我如果直接赋值<br>filename:='d:/output/111.jps'<br>path:='d:/output';<br>就可以;<br>???????????????????????????????????????
 
调用时是不是Mainfrm.FilenameEdt.FileName还没有初始化,活着已经释放了?
 
老大,你是不是少写一个斜杠啊,ExtractFileDir是不带斜杠的返回啊!再加一个!!
 
获得当前应用程序文件名是下面<br>application.ExeName<br>获得当前应用程序路径是下面这个<br>extractfilepath(application.ExeName)<br><br>使用extractfilepath得到的路径包含“/”。<br><br>你应单步执行一下,看看得到的路径是否正确。
 
我把获得的filename、path、par全部用label显示过,<br>我如果直接把显示的filename、path、par直接赋值就可以完成执行
 
&nbsp;ShellExecute(Application.MainForm.Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'open',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'jps.exe',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;par,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SW_Hide<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); <br>
 
D影子D:<br>&nbsp; &nbsp; &nbsp; 不行的。WinApi调用时必须把字符的格式改为PChar格式!!!!~~~~
 

Similar threads

后退
顶部