ShellExecute 命令在 win10 中无法正常工作 [英] ShellExecute Command doesn't work properly in win10

查看:85
本文介绍了ShellExecute 命令在 win10 中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 shellexecute 命令打开一个文件,我的代码是

I m trying to open a file using shellexecute command my code is

ShellExecute(NULL,NULL,itemPath,NULL,NULL,SW_SHOW); 

ShellExecute(NULL,L"open",itemPath,NULL,NULL,SW_SHOW); 

两种方式我都用过,但是当我给出一个文件夹的路径时,它会打开一个文件夹,但是当我给出一个文件的完整指定路径时,它不起作用.如果我给出一个硬编码路径,例如

I have used both ways but when I m giving path of a folder it opens a folder but when I m giving a full specified path of a file it doesn't work. one thing more if I m giving a hardcode path like for example

ShellExecute(NULL,L"open",L"E:\\abc.xlsx",NULL,NULL,SW_SHOW);

然后打开这个文件.任何人都可以解释为什么会发生这种情况.

than it opens this file. can any one explain why it is happening.

推荐答案

ShellExecute 工作正常,并且可以在您的代码中找到缺陷.唯一有意义的解释是 itemPath 不是您认为的那样.如果它确实是一个指向包含 L"E:\\abc.xlsx" 的以空字符结尾的字符数组的指针,那么 ShellExecute 将按您的预期运行.

ShellExecute works correctly, and the defect can be found in your code. The only explanation that makes sense is that itemPath is not what you think it is. If it were indeed a pointer to null-terminated character array containing L"E:\\abc.xlsx" then ShellExecute would behave as you expect.

您可以通过检查 itemPath 的内容来调试问题,找出它真正包含的内容.如果您提供了 MCVE,那么我们可以更具体地诊断问题.

You can debug the problem by inspecting the content of itemPath to find out what it really contains. Were you to have provided an MCVE then we could have been more specific in the diagnosis of the problem.

最后,ShellExecute 已被弃用,主要是因为它没有提供报告失败条件的好方法.您应该改用 ShellExecuteEx.

Finally, ShellExecute is deprecated, largely because it provides no good means of reporting failure conditions. You should use ShellExecuteEx instead.

这篇关于ShellExecute 命令在 win10 中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆