CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    [RESOLVED] .ini & SaveBarState problem

    Hi!

    I´m developing an aplication where I save the bar state to a .ini file. Im setting m_pszProfileName = ::_tcsdup(_T(".\\MYAPLICATION.ini")) to avoid using the registry. The problem is that VS is creating the file not alowing to the commum users to write to the file. This way, for the commum user of my aplication the new state of the bars are not being saved. If I run the aplication as administrator the problem does not happen (I cheked the permitions of the file and for commun users writing is not alowed). Is there any command on the MSVC C++ to create this file alowing the commum user to write to the file? My goal is alow the commum user of my aplication to have the bar state saved transparently without need to call my aplication as an administrator.

    Thank you

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: .ini & SaveBarState problem

    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Re: .ini & SaveBarState problem

    Thank you for answering.

    I´m using Windows 7 and as on that blog I should save the ini file on "%USERPROFILE%\AppData\Roaming\<MyCompany>\<MyApp>" but it is not working. The toolbars state is not being saved. I changed the path to:

    m_pszProfileName = ::_tcsdup(_T("%USERPROFILE%\\AppData\\Local\\Company\\Aplication\\Aplication.ini"));

    is this correct? The \\ are required and the USERPROFILE as a system variable may be sourronded by %, rigth?

    Thank you

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: .ini & SaveBarState problem

    Just look at the debugger/output window the string m_pszProfileName points to after ::_tcsdup(...).
    Is it what you expected?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Re: .ini & SaveBarState problem

    It does not change. The "%" simbol remains in the string. I expected that this variable (USERPROFILE) to be expanded to its value. In the tcsdup it is not. I debuged deep in the LoadStdProfileSettings(4) (where the .ini is loaded) and the % remain on the path, so I guess I will need to get the value of this enviroment variable by myself. I´m going to do this and let´s see if will work.

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: .ini & SaveBarState problem

    Why not use SHGetKnownFolderPath() to obtain the correct path to "%USERPROFILE%\AppData\Roaming\" for the various OS versions (since Vista) with parameter FOLDERID_RoamingAppData. See https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    Consider example
    Code:
    #include <ShlObj.h>
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	PWSTR wnm;
    	SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &wnm);
    
    	wcout << wnm << endl;
    
    	CoTaskMemFree(wnm);
    }
    which on my system displays
    Code:
    C:\Users\admin1\AppData\Roaming
    The application specific part can then be appended to this.

    PS Why change roaming to local?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Re: .ini & SaveBarState problem

    I think this is exately what I need. I´ll try it.


    Thank you

  8. #8
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Re: .ini & SaveBarState problem

    Ok, it worked. I got the correct path and the .ini file is being saved with all permitions for all kind of users.

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured