有关 Shellexecute( ) 的问题(50分)

W

wuyi

Unregistered / Unconfirmed
GUEST, unregistred user!
下面的程序是在一个POPMENU中执行的, 当执行到该过程返回的END时, 出现<br><br>以下信息并只有用RUN菜单下的PROGRAM RESET恢复, 用单步跟踪也不行.<br><br>Project myproject raised exception class &nbsp;c0000005 &nbsp;with<br>message 'access violation at oxbff76ece: read of address <br>oxffffffff'. Process stopped. Use Step or Run to continue.<br><br>而用Shellexecute(hinstance,'open','netscape.exe',pchar(filename),'e:',SW_SHOWDEFAULT);<br><br>时不会出错, 请大侠们会诊一下.<br><br><br>procedure TMainForm.AttachListDblClick(Sender: TObject);<br>var filename:string;<br>&nbsp; &nbsp; dirlen: integer;<br>&nbsp; &nbsp; curdir :array[0..100] of Char;<br>begin<br>&nbsp; with attachList do<br>&nbsp; if AttachList.ItemFocused &lt;&gt; nil then<br>&nbsp; begin<br>&nbsp; &nbsp; dirlen := GetCurrentDirectory(sizeof(curdir),curdir);<br>&nbsp; &nbsp; FileName:=copy(curdir,1,dirlen)+'/attach/'+AttachList.ItemFocused.caption;<br>&nbsp; &nbsp; Shellexecute(hinstance,'open',PChar(FileName),'','e:',SW_SHOWDEFAULT);<br>&nbsp; end;<br>end;<br>
 
ShellEcecute是API函数调用时应注意使用PChar, 为空时应用 nil 而不是 ''<br><br>如:<br>&nbsp; ShellExecute(Application.Handle,<br>&nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp;PChar('C:/aaa.exe'),<br>&nbsp; &nbsp; &nbsp;PChar('Parameter '),<br>&nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp;SW_SHOW);<br>
 
shellexecute是WINDOWS API函数,参数必须是PCHAR类型。
 
我发现只要执行一个可执行文件时不会有问题, 否则就会......<br><br>请再帮帮我!
 
没人成功过吗?
 
pchar为空时的确应该置nil.<br>xixi说的不错.下面是我调用成功的例子:<br><br>Shellexecute( self.handle, 'open' , <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PChar('D:/dream.html'),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil,'e:',SW_SHOWDEFAULT);
 
TO茶叶蛋:<br><br>&nbsp; &nbsp; 我试了一下, 还是老毛病. 你能否给我你的"调用成功的例子"?
 
TO茶叶蛋:<br><br>&nbsp; &nbsp; 我试了一下, 还是老毛病. 你能否给我你的"调用成功的例子"?
 
例子已发往您的信箱,30秒钟以前我刚试过,它把我的ie调出来了.
 
"它把我的ie调出来了", 然后有没出错.<br><br>我的就是出问题, 不知是不是win98下的问题.
 
我发现在IDE下运行会出错, 而在windows下直接运行就不会出错.<br><br>是不是我的d4有什么设置不对?
 
对啊,我用的是win97OSR2耶<br><br>我刚才在BiJ的机子上试了一下.<br>(标准的win95,里面的ie3时我装的)<br>结果把他今天装的opera给调出来了.
 
&gt;是不是我的d4有什么设置不对?<br><br>很有可能.
 
谢谢各位.
 
多人接受答案了。
 
顶部