简体   繁体   中英

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? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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