Relative Path of Windows program

Source: Internet
Author: User

A problem occurred in a recent program. When the select file dialog box is opened, the Log Module reports an I/O error and checks it online,

I am not familiar with the underlying mechanism of Windows because of problems caused by the use of the relative path in http://bbs.csdn.net/topics/290069179:

1. if setcurrentdirectory is not actively called, the current path is the initial path specified when the process starts, this path is not necessarily the directory where the main program of the process is located (For details, refer to the eighth parameter in CreateProcess );

2. Generally, the dialog is set to modify the current path. Therefore, when you choose to confirm, the current path will be changed to the (selected) path shown on the dialog.

Generally speaking, using this uncertain relative path is very insecure. Any execution unit may adjust the current path by explicitly or implicitly calling setcurrentdirectory, A better way is to obtain a specific relative path (including the current application, current user, and so on) by using the environment variable or getmodulefilename, and then calculate it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.