Thread: Can anyone take a look at this? I´m stuck with GetPrivateProfileString problems

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    Can anyone take a look at this? I´m stuck with GetPrivateProfileString problems

    I have reduced the code to a very simple example with only one control in order to expose my problem in a clearer way.
    The whole purpose of this thing is to use GetPrivateProfileString to read values from a ini and set them in vars. Then create all my mainwindow controls and call VarsToControls to adjust their state.
    And when i close my app, it will get the current state of the controls and write the to the ini using WritePrivateProfileString before exiting.
    Maybe it´s something simple, i don´t know... 2 entire days looking at the whole code, i´m beginning to get lost here.
    Any help will be great

    Code:
    //char strCB1[2]; //This is declared at main.h 
    
    ------------iniIO.h------------------
    int ini_read() { //This is called from main.c before the controls are created. 
    GetPrivateProfileString("CheckBox1", "state", "1", strCB1, 2, "C:\\myapp\\myapp.ini"); 
    return 0; 
    } 
    
    int VarsToControls() { //This is called from main.c after the controls are created. 
    if (strCB1==1) { 
    MessageBox (NULL, TEXT (strCB1), "strCB1 is equal to 1", MB_ICONERROR); 
    //Theres code doing stuff here, setting edit fields as enabled/disabled, etc// 
    } 
    else { 
    MessageBox (NULL, TEXT (strCB1), "strCB1 is not equal to 1", MB_ICONERROR); 
    //Theres code doing stuff here, setting edit fields as enabled/disabled, etc// 
    } 
    return 0; 
    } 
    -----------------------------------------------------------
    Here´s the thing: I have placed this msbBoxes there to try to understand whats going on with my code. I always get the "strCB1 is not equal to 1" msgBox, and it shows me the value of strCB1 as 1
    No compilor error or warnings using DEV-CPP (mingw 2.0, gcc3.2).

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    if (strCB1==1) is the problem

    if(strstr(strCB1,"1")!=NULL)//match

    if(atoi(strCB1)==1)//match

    if(strCB1[0]=='1')//match
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    I was dealing with a string and not with a integer is that it? Anyway i used if(strCB1[0]=='1')//match solution and that solved a lot, things are starting to make sense here. The checkboxes and editfields are getting their state and contents from the vars. That function is called VarsToControl and its working 100% now.

    What i want now is to do the opposite function which will get the state of the controls and set on that vars. It will be called ControlToVars.

    In that function i need to set strCB1[0] with 0 or 1, deppending on the result of SendMessage(hwndCB1, BM_GETSTATE, (WPARAM)0 ,(LPARAM)0);


    But if i can "if(strCB1[0]=='1'){ stuff }" why can´t i
    strCB1[0] = (SendMessage(hwndCB1, BM_GETSTATE, (WPARAM)0 ,(LPARAM)0)); ?

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I was dealing with a string and not with a integer is that it?

    Yes

    You can't make a apple an orange without some modifications.

    You can't make an 'int' variable a 'char' varable without some modifications.

    SendMessage() returns an int.
    Code:
    if(SendMessage(hwndCB1, BM_GETSTATE, (WPARAM)0 ,(LPARAM)0)==BST_CHECKED)
            strCB1[0]='1';
    watch for BST_INDETERMINATE ect returns.


    I would convert the ini values to more usable data types and store in a struture or an array of ints
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. Replies: 6
    Last Post: 10-23-2006, 07:22 PM
  3. Coding Problems
    By RpiMatty in forum C++ Programming
    Replies: 12
    Last Post: 01-06-2002, 02:47 AM
  4. String and char* problems
    By Dreamerv3 in forum C++ Programming
    Replies: 4
    Last Post: 01-03-2002, 08:36 PM