简体   繁体   English

C ++调用ShellExecute而不指定路径

[英]c++ calling ShellExecute without specifying path

i got a file name that is predefined as a string. 我得到了预定义为字符串的文件名。 can i call shellexcute without specifying the full path? 我可以在不指定完整路径的情况下调用shellexcute吗? like: 喜欢:

ShellExecute(NULL, L"open", PreDefiendFileName, NULL, NULL, 0);

what should i do otherwise if not? 如果没有,我该怎么办?

You could: 你可以:

  1. Fail gracefully: let the user know that the file could not be found and halt the program. 正常失败:让用户知道找不到该文件并暂停程序。
  2. Use a default file that you *know* is there, and inform the user that you are using the default file. 使用您*知道*的默认文件,然后通知用户您正在使用默认文件。

I'd encourage you to think defensively about this problem. 我鼓励您对这个问题采取防御性的思考。 Eg ensure that the file name that is passed is actually a file ("does it have the correct extension?", "does it exist in the file system?") and then only call the ShellExecute function if those checks pass. 例如,确保传递的文件名实际上是一个文件(“扩展名正确吗?”,“文件系统中是否存在?”), 然后仅在这些检查通过的情况下才调用ShellExecute函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM