Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6183147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:19:02+00:00 2026-05-24T01:19:02+00:00

Is my code correct? It seems can compile but does not work properly.. CString

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:19:03+00:00Added an answer on May 24, 2026 at 1:19 am

    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 takes KNOWNFOLDERID values to identify the folder whose path you wish to retrieve. In your case, that would be FOLDERID_Profile.

    If you need to target earlier versions of Windows (such as XP), you will need to use the SHGetSpecialFolderPath function, instead. It takes a CSIDL value identifying the folder whose path you wish to retrieve. Again, in your case, that would be CSIDL_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_APPDATA or CSIDL_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:

    TCHAR szFolderPath[MAX_PATH];
    if (!SHGetSpecialFolderPath(NULL, szFolderPath, CSIDL_APPDATA, FALSE))
    {
        // Uh-oh! An error occurred; handle it.
    }
    

    Or, using MFC’s CString class:

    CString buffer;
    BOOL bRet = SHGetSpecialFolderPath(NULL, buffer.GetBuffer(MAX_PATH), CSIDL_APPDATA, FALSE);
    buffer.ReleaseBuffer();
    if (!bRet)
    {
        // Uh-oh! An error occurred; handle it.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell how correct the following code below. Iam tryin to create a
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Suppose you have legacy java code which can not be compiled by an up-to-date
For chrome, firefox, and safari the following code seems to work and be able
Which is the most correct code? if (HttpContext.Current.Response.Cookies[authCookieName] != null) { HttpContext.Current.Response.Cookies[authCookieName].Value = New
Links to point me in the correct direction, or sample code will be appreciated.
Is there a way to reformat code, i.e. force correct indentation in FlashDevelop as
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
Code below is not working as expected to detect if it is in design
I'm getting the error: 'Namespace.A' does not contain a definition for 'MyObjectInterface' and no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.