CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2004
    Location
    Germany
    Posts
    16

    Red face Save data for next session

    Hi, i just switched from VC6 to .NET 2 (2005 edition). Besides a lot of other things i have problems to get used to the all new techniques. I want to store a value in a dialog for the next session with my app.
    Befor i used WriteProfileInt from the Windows SDK i.e. and in the OnInitDialog i loaded the value with GetProfileInt from the SDK.
    What do i have to do in .NET?
    I read something about configuration .config XML files etc. but did not find a easy way to store the data when exiting the app.

    Please help
    Last edited by gintonic42; September 27th, 2006 at 05:32 AM.

  2. #2
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Save data for next session

    As a first simple solution you could use Microsoft::Win32::Registry and Microsoft::Win32::RegistryKey :

    http://msdn2.microsoft.com/en-us/lib...y_members.aspx
    http://msdn2.microsoft.com/en-us/lib...y_members.aspx

    It might be an idea to create your own settings class, where each setting is represented externally as a property. Internally it could use the registry but later on could be changed to use XML config files instead.
    Last edited by Zaccheus; September 27th, 2006 at 04:33 PM.
    My hobby projects:
    www.rclsoftware.org.uk

  3. #3
    Join Date
    May 2004
    Location
    Germany
    Posts
    16

    Re: Save data for next session

    Hy Zaccheus,
    is there an easy example to approach my own settings class?

  4. #4
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Save data for next session

    Here's a simplified version of what I use:
    Code:
    // .h
    
    public ref class ApplicationConfiguration
    {
    public:
        static System::String^ ReadString
            (
            System::String^ inKeyName,
            System::String^ inValueName,
            System::String^ inDefault
            );
        static void WriteString
            (
            System::String^ inKeyName,
            System::String^ inValueName,
            System::String^ inValue
            );
    private:
       /////////////////////////////////////////////////////////////////
       // Choose your own company name and application name.
       /////////////////////////////////////////////////////////////////
        static System::String^ baseName = L"HKEY_CURRENT_USER\\Software\\MYCOMPANYNAME\\MYAPPNAME\\";
    };
    
    // .cpp
    
    System::String^ ApplicationConfiguration::ReadString
        (
        System::String^ inKeyName,
        System::String^ inValueName,
        System::String^ inDefault
        )
    {
        System::Object^ result = Microsoft::Win32::Registry::GetValue(baseName + inKeyName, inValueName, inDefault);
        
        return dynamic_cast<System::String^>(result);
    }
    
    void ApplicationConfiguration::WriteString
        (
        System::String^    inKeyName,
        System::String^    inValueName,
        System::String^    inValue
        )
    {
        Microsoft::Win32::Registry::SetValue(baseName + inKeyName, inValueName, inValue, Microsoft::Win32::RegistryValueKind::String);
    }
    Obviously you would replace MYCOMPANYNAME and MYAPPNAME with something meaningful.
    My hobby projects:
    www.rclsoftware.org.uk

  5. #5
    Join Date
    May 2004
    Location
    Germany
    Posts
    16

    Re: Save data for next session

    Thanks for that, but this is not exactly, what i am looking for. I dont want a workaround for that, i would like to use the "normal" mechanism.
    I have found out something new.
    In VS opening a dialog in design mode, an edit box has a property called ApplicationSettings->PropertyBinding, where you can setup application settings. This seems to be the mechanism, that uses these .config xml files for the properties. But this does not work on my system. If i try to add a new setting, i get an error message:
    In my german system:
    "Im Projekt wurden keine Einstellungsdateien gefunden. Fügen Sie eine Einstellungdatei hinzu, und wiederholen Sie den Vorgang." which says:
    There is no settings file in the project. Add one and try again.
    In the help it is said, to use the Project-Designer for that, but i have no project designer and the method in the helpfile seems to talk of a different compiler. My VS has no project designer.
    Does anybody know this problem?

  6. #6
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Save data for next session

    Ok, I thought you just want a simple replacement for INI files.


    I have not yet investigated the technique you are talking about, but it sounds like I should.
    My hobby projects:
    www.rclsoftware.org.uk

  7. #7
    Join Date
    Sep 2006
    Posts
    17

    Re: Save data for next session

    Throw on form TextBox, click on it further in a window of properties open ApplicationSettings, and for property Text set create new adjustment. Thus property Text will be connected with My. Settings.
    Not having written a uniform line of a code, the data from this text field will be stored in adjustments.

    Probably something is done not so?

  8. #8
    Join Date
    May 2004
    Location
    Germany
    Posts
    16

    Re: Save data for next session

    Hy, i was a little on holiday.
    If i try to do so, i get an error message like described above. I do not have a design manager. What is that? There is nothing with that name in my environment. I am using VS 2005 with VC++ 2005. Are you talking about the same version?
    Your technique seems to be, what i am searching for, but it does not work on my computer.

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