Is my code correct? It seems can compile but does not work properly..
CString testing = _T(" --url=") + cstring + _T(" --out=%USERPROFILE%\\snapshot.png");
I want to point it to user’s folder..but still cannot work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The answer is that you don’t use environment variables at all. Rather, you use the shell functions specifically designed to retrieve the path of special folders.
On Windows Vista and later, that function is
SHGetKnownFolderPath. It takesKNOWNFOLDERIDvalues to identify the folder whose path you wish to retrieve. In your case, that would beFOLDERID_Profile.If you need to target earlier versions of Windows (such as XP), you will need to use the
SHGetSpecialFolderPathfunction, instead. It takes a CSIDL value identifying the folder whose path you wish to retrieve. Again, in your case, that would beCSIDL_PROFILE.Of course, you should never store data directly in the user’s profile folder. So hopefully the bit of code that you’ve shown is for demonstration purposes only. Applications should only create files in the specific locations under the user profile folder, designed for application data storage.
These locations are
CSIDL_APPDATAorCSIDL_LOCAL_APPDATA. If you are creating data that the user should be able to modify and should treat as his/her own, then it would be appropriate to store that data in the user’s documents folder (CSIDL_MYDOCUMENTS).More usage information is available in my answer here.
Sample code:
Or, using MFC’s
CStringclass: