get "application data" directory in xp, vista

This is a discussion on get "application data" directory in xp, vista within the Windows Programming forums, part of the Platform Specific Boards category; hi, all as you know, some folder has different path in winxp and vista. i get path for application data ...

  1. #1
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58

    get "application data" directory in xp, vista

    hi, all
    as you know, some folder has different path in winxp and vista.
    i get path for application data directory (in winxp, but appdata in vista) using SHGetSpecialFolderPath api function.

    Syntax

    BOOL SHGetSpecialFolderPath( HWND hwndOwner,
    LPTSTR lpszPath,
    int nFolder,
    BOOL fCreate
    );
    Parameters

    hwndOwner
    Handle to the owner window the client should specify if it displays a dialog box or message box.
    lpszPath
    Pointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.
    nFolder
    A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.
    fCreate
    Indicates if the folder should be created if it does not already exist. If this value is nonzero, the folder will be created. If this value is zero, the folder will not be created.
    then nFolder has const variable like "CSIDL_LOCAL_APPDATA" for getting path for winxp.
    but this value dont work in vista.
    can you suggest how to solve this problem?
    any help will be appreciate.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    This question should be asked in the Windows Programming forum.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Moved
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    I use the code below for win98se straight thru to vista and I've never had a problem finding the apps directory. May not be the best method, but it works. All I ever noticed with vista (and thankfully I don't own that piece of crap) is it has a tendancy to hide files inside the compatibility tab's folder.

    Code:
    std::string getDrivePath;
    
         char Path[MAX_PATH];    /* Default Size - GetCurDirect */
         GetModuleFileName(NULL, Path, MAX_PATH);
         getDrivePath=Path;
         std::string::size_type loc= getDrivePath.find_last_of("\\");
         getDrivePath.erase(loc+1);   /* Retain full pathway  */

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    However, this isn't "application data" folder (as in %appdata%), which is what the OP was after.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Well, if it's his/her application then he/she should know what the data folder is, so simply append that to the getDrivePath string. Or, perhaps I'm misinterpreting the OP's question altogether. Dunno, it's been a long day. ..

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    In the description of the function is stated that starting with Win2K this function is superseeded by SHGetFolderPath - try to use this function...
    Also check that you call the UNICODE version, Vista could have problems with ANSI support...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Quote Originally Posted by Oldman47 View Post
    Well, if it's his/her application then he/she should know what the data folder is, so simply append that to the getDrivePath string. Or, perhaps I'm misinterpreting the OP's question altogether. Dunno, it's been a long day. ..
    No no no.
    Typically it's the one locared at %systemroot%\Documents and settings\User\Application Data (on XP).
    You can get it by typing %appdata% too.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    sgh
    sgh is offline
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    i cannt get properly information for your reply.
    my code says like
    .......
    Code:
    switch(type)
      {
        case APPLICATION_DATA:
          folder = CSIDL_APPDATA; break;
        case LOCAL_SETTINGS_APPLICATION_DATA:
          folder = CSIDL_LOCAL_APPDATA; break;
        //unhandeled folder type
        default:
          return false;
      }
    
      //call unicode or local-specific functions as necessary to get folder path
      bool success = true;
    
      //So KwangHyok Update Code - 2008/3/12
      QLibrary library("shell32");
      typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPTSTR, int, BOOL);
      GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
    as you know CSIDL_LOCAL_APPDATA and CSIDL_APPDATA is available in winxp, but not in vista.
    MSDN says CSIDL_LOCAL_APPDATA is "C:\Documents and Settings\username\Local Settings\Application Data"
    so i need to know how to use another value instead of CSIDL_LOCAL_APPDATA or any way.
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to Install XP over Vista with SATA HD
    By Shamino in forum Tech Board
    Replies: 2
    Last Post: 12-13-2008, 05:56 PM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  3. Vista design being forced on XP?
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 128
    Last Post: 03-04-2008, 11:56 AM
  4. Windows XP (and Vista) shiney look and feel
    By lightatdawn in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 09-18-2005, 02:56 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21