dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: config file

  1. #1
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    config file

    I was wondering how to store info, which is text data, in some sort of config file for my c++ program. I don't want to hardcode it, and i have i think too much info to use the registry. I was wondering how commercial programs would do this. Obviously i could use a text file, buit then that isn't very secure commercially. I needs to be easily changed by hand if neds be.

    Cheers,

    David.
    With sufficient thrust, pigs fly just fine. However, this is not
    necessarily a good idea. It is hard to be sure where they are going to
    land, and it could be dangerous sitting under them as they fly
    overhead. -- RFC 1925

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: config file

    Quote Originally Posted by dave2k
    I was wondering how to store info, which is text data, in some sort of config file for my c++ program. I don't want to hardcode it, and i have i think too much info to use the registry. I was wondering how commercial programs would do this.
    As far as I know there are more and more applications out there using XML-files to store information/configuration.

    Quote Originally Posted by dave2k
    Obviously i could use a text file, buit then that isn't very secure commercially.
    What do you mean?

    Quote Originally Posted by dave2k
    I needs to be easily changed by hand if neds be.
    Well, XML-files can be easily changed by hand, but ofcourse it's your responsibility to make a "human readable" structure of your data.

  3. #3
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: config file

    Quote Originally Posted by dave2k
    I was wondering how commercial programs would do this.
    Old commercial software uses Ini files/registry (I have seen application storing files in the registry ). New modern software counts on XML. And if you call the unix environment your home, you'd rather use text files with a custom format.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: config file

    files were the norm at one time. Then MS said, please use registry for such things, hence came the HKLM\SOFTWARE location for apps to dump their stufff. Then came all the qoes of using registry and their misuse and then MS said, enough is enough.. please use config files again ( read .Net ).

    If security is an issue.. you can store data with some form of encryption.

  5. #5
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: config file

    Quote Originally Posted by kirants
    files were the norm at one time. Then MS said, please use registry for such things, hence came the HKLM\SOFTWARE location for apps to dump their stufff. Then came all the qoes of using registry and their misuse and then MS said, enough is enough.. please use config files again ( read .Net ).

    If security is an issue.. you can store data with some form of encryption.
    A very good point though. The only problem I have with the registry: The lack of shiping conifguration. Exporting them and importing them is a great circumstance. That's why still some app's (like eMule and others) still use INI files: They are easy to ship and also easy to edit. Apart from that, that they are easy to access from code: Two functions do the trick.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: config file

    NoHero brings up some good points here.

    From the discussions I see here, I see 2 parts. One, storing info and two, ease of access. Ease of access can have 2 faces . One, ease of access via code. Two, ease of access for end user.

    I would do this:
    I wouldn't bother too much of the ease of access via code. I don't consider it a factor here.
    More important here is , access to end user. Does the end user need access to such info and should s/he be able to manipulate them. If so, I would take the approach of ini/xml/config files in human readable form. If not, I would take the approach of registry. Also, if some form of export/import is involved file approach makes more sense..

  7. #7
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: config file

    Are the .ini files plain text? Also, are there any API methods to access either of these? if not, are there any other simple apis? I am trying to keep my code as leightweight as possible.
    With sufficient thrust, pigs fly just fine. However, this is not
    necessarily a good idea. It is hard to be sure where they are going to
    land, and it could be dangerous sitting under them as they fly
    overhead. -- RFC 1925

  8. #8
    Join Date
    May 2005
    Posts
    4,954

    Re: config file

    Quote Originally Posted by dave2k
    Are the .ini files plain text?
    Yes

    Quote Originally Posted by dave2k
    Also, are there any API methods to access either of these? if not, are there any other simple apis?
    Yes look at:

    • ::GetPrivateProfileInt(...)
    • ::GetPrivateProfileSection(...)
    • ::GetPrivateProfileSectionNames(...)
    • ::GetPrivateProfileString(...)
    • ::GetPrivateProfileStruct(...)
    • ::GetProfileInt(...)
    • ::GetProfileSection(...)
    • ::GetProfileString(...)
    • ::WritePrivateProfileSection(...)
    • ::WritePrivateProfileString(...)
    • ::WritePrivateProfileStruct(...)
    • ::WriteProfileSection(...)
    • ::WriteProfileString (...)


    here is the link:
    Registry Functions
    just scroll it down...



    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  9. #9
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: config file

    not the registry, for ini files
    With sufficient thrust, pigs fly just fine. However, this is not
    necessarily a good idea. It is hard to be sure where they are going to
    land, and it could be dangerous sitting under them as they fly
    overhead. -- RFC 1925

  10. #10
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: config file

    The listed functions are a part of the Registry Functions, but they are actually writing/reading to/from .ini files.

    - petter

  11. #11
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: config file

    Any Possible examples anywhere of reading to normal text file useing these functions?
    With sufficient thrust, pigs fly just fine. However, this is not
    necessarily a good idea. It is hard to be sure where they are going to
    land, and it could be dangerous sitting under them as they fly
    overhead. -- RFC 1925

  12. #12
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: config file

    Quote Originally Posted by dave2k
    Any Possible examples anywhere of reading to normal text file useing these functions?
    Ini files:
    Code:
    [MySection]
    MyKey=MyValue
    Code:
    Code:
    TCHAR szChar[100] = TEXT("");
    GetPrivateProfileString(TEXT("MySection"), TEXT("MyKey"), TEXT(""), szChar, sizeof(szChar) / sizeof(TCHAR) - 1, TEXT("myinifile.ini"));
    Of course you can leave the support for TChar's out.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  13. #13
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: config file

    Wicked cheers!
    With sufficient thrust, pigs fly just fine. However, this is not
    necessarily a good idea. It is hard to be sure where they are going to
    land, and it could be dangerous sitting under them as they fly
    overhead. -- RFC 1925

  14. #14
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    Re: config file

    i have
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        char szChar[100];
        GetPrivateProfileString("section", "key", "none", szChar, 999, "ini.ini");
        cout << szChar << endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    my ini.ini file contains
    [section]
    key=string


    but it keeps echoeing none

    why is this?

    cheers
    With sufficient thrust, pigs fly just fine. However, this is not
    necessarily a good idea. It is hard to be sure where they are going to
    land, and it could be dangerous sitting under them as they fly
    overhead. -- RFC 1925

  15. #15
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: config file

    What does GetLastError() return?
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

Page 1 of 2 12 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)