CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Unhappy How does WriteProfileString() works...???

    Hi all,

    I am using WriteProfileString() function call in my application... Microsoft SDK says that : The WriteProfileString function copies a string into the specified section of the Win.ini file ..

    But when i opened the file Win.ini .. i don't see any section or entry created. However when i use GetProfileString() function call i can fetch the data stored by WriteProfileString()...

    So my question is where can i see the contents written by WriteProfileString()..

    I also searched under Registry editor for my the contents... but could'nt find...

    Please anybody explain me this....

    Thanks,

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

    Re: How does WriteProfileString() works...???

    Have a look at the InitInstance method of your App: if SetRegistryKey(...) call is there and not commented out then registry is used rather than win.ini file. See MSDN article "CWinApp::SetRegistryKey" for details.
    Last edited by VictorN; June 25th, 2009 at 11:24 AM.
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Unhappy Re: How does WriteProfileString() works...???

    No, there is not call to SetRegistryKey() .... Anyway in registry where can i look for the data written by WriteProfileString().

    BTW i am call the fun like this:

    CWinApp* pApp = AfxGetApp();
    pApp->WriteProfileString(_T("Section_Name "),_T("Entry"),_T("Value"));

    Any clue...

    Thanks,

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

    Re: How does WriteProfileString() works...???

    Did you read MSDN article "CWinApp::SetRegistryKey" or not?
    Anyway, you could debug your code stepping into the WriteProfileString() function and so on to see what and why happens.
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Red face Re: How does WriteProfileString() works...???

    Thanks for all of your efforts Victor_N, Those info were really helpful....

    Also i found that the application creates an "App_Name.ini" file in "C:\Windows" and its doing read and write via this ini file and earlier i was confused looking into Win.ini file.

    So WriteProfileString() creates a file with "App_Name.ini" and write the data into it not in Win.ini

    Is it correct...???

    Thanks,

  6. #6
    Join Date
    Jun 2009
    Posts
    8

    Re: How does WriteProfileString() works...???

    Remarks

    Call this member function to write the specified string into the specified section of the application’s registry or .INI file.

    The entries are stored as follows:

    In Windows NT, the value is stored to a registry key.


    In Windows 3.x, the value is stored in the WIN.INI file.


    In Windows 95, the value is stored in a cached version of WIN.INI.
    Example

    CString strSection = "My Section";
    CString strStringItem = "My String Item";
    CString strIntItem = "My Int Item";

    CWinApp* pApp = AfxGetApp();

    pApp->WriteProfileString(strSection, strStringItem, "test");

    CString strValue;
    strValue = pApp->GetProfileString(strSection, strStringItem);
    ASSERT(strValue == "test");

    pApp->WriteProfileInt(strSection, strIntItem, 1234);
    int nValue;
    nValue = pApp->GetProfileInt(strSection, strIntItem, 0);
    ASSERT(nValue == 1234);

  7. #7
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Red face Re: How does WriteProfileString() works...???

    Quote Originally Posted by fanronghua View Post
    Remarks

    Call this member function to write the specified string into the specified section of the application’s registry or .INI file.

    The entries are stored as follows:

    In Windows NT, the value is stored to a registry key.


    ;
    Yes thats true, But in my case i can see the values are getting stored in MyApp_Name.ini file under windows directory.

    I think as Victor_N said in his above posts if we use SetRegistryKey() function, the values will be stored under the configured reg key... If not set values will be stored in an .ini file.

    The only thing i want to confirm is that the ini file will be the Win.ini or App_Name.ini(as i can see in my application)...

    Thanks,

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