Read info from ini with specified range

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iktNL
    New Member
    • Oct 2011
    • 2

    #1

    Read info from ini with specified range

    Well hello =)

    I want to read out values in an ini with a user specified value.

    Let's say this is the ini:
    Code:
    [Options]
    AmountAdded=2
    
    [AddedCars]
    1=carderp
    2=apples
    Now I think using a for loop is okay, but MS Visual C++ 2010 doesn't like me using variables in the function GetPrivateProfi leString.

    This is how the piece of code is:
    Code:
    GetPrivateProfileString("AddedCars",string(AmountAdded),NULL,Car1,128,"./TrafficLoad.ini");
    However, as you maybe can see, GetPrivateProfi leString only accepts the 'where to look' if it's within quotes. Any way I can circumfence this? (Of course, AmountAdded increases everytime it's looping)
    Thank you =)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This is the function prototype of GetPrivateProfi leString:

    Code:
    DWORD WINAPI GetPrivateProfileString(
      __in   LPCTSTR lpAppName,
      __in   LPCTSTR lpKeyName,
      __in   LPCTSTR lpDefault,
      __out  LPTSTR lpReturnedString,
      __in   DWORD nSize,
      __in   LPCTSTR lpFileName
    );
    For lpAppName you need an LPCTSTR but you provided a char*.
    For lpKeyName you need an LPCTSTR but you provided an STL string object.
    etc...

    Until you provide the correct types for your arguments you will contnue to have difficulty.

    I expect you will need to include <TCHAR.h> and use the TCHAR substitutions provided by Microsoft. Info is in MSDN and is very complete.

    Comment

    • iktNL
      New Member
      • Oct 2011
      • 2

      #3
      Thank you! It worked!

      Comment

      Working...