Click here to Skip to main content
15,905,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create one Ini file, but it is not performing any read write operation on this file.
When I debug that code it shows that value of theApp.m_pszRegistryKey is 0. I used eVC 4.0 which support only WriteProfileString of application object. How to set the registry key? Help me.

[edited]
Please find the code below

C++
CFile obFile;
BOOL bResult = FALSE;
 
if( obFile.Open( strAppIniPath, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite ))
{
AfxMessageBox(_T("File Opened"),IDOK,NULL); 
bResult = theApp.WriteProfileString(_T("General"), _T("FirstName"), _T("ABC"));
 
if(bResult)
AfxMessageBox(_T("Text Written"),IDOK,NULL);
else
AfxMessageBox(_T("Text not Written"),IDOK,NULL);
 
bResult = theApp.WriteProfileString(_T("General"),_T("LastName"), _T("XYZ"));
 
if(bResult)
AfxMessageBox(_T("Text Written"),IDOK,NULL);
else
AfxMessageBox(_T("Text not Written"),IDOK,NULL);
}
else
AfxMessageBox(_T("Unable to Open File"),IDOK,NULL);
Posted
Updated 9-Apr-12 23:21pm
v2
Comments
Richard MacCutchan 10-Apr-12 3:48am    
Without seeing the code that is not working it's impossible to guess what the problem may be. Please edit your question and add some more detailed information.
Resmi Anna 10-Apr-12 5:24am    
Question is edited.

1 solution

please try as below

C++
CFile obFile;
BOOL bResult = FALSE;
CWinApp* pApp = AfxGetApp();

if( obFile.Open( strAppIniPath, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite ))
{
	AfxMessageBox(_T("File Opened"),IDOK,NULL); 
	bResult = pApp->WriteProfileString(_T("General"), _T("FirstName"), _T("ABC"));
 
	if(bResult)
		AfxMessageBox(_T("Text Written"),IDOK,NULL);
	else
		AfxMessageBox(_T("Text not Written"),IDOK,NULL);
 
	bResult = pApp->WriteProfileString(_T("General"),_T("LastName"), _T("XYZ"));
 
	if(bResult)
		AfxMessageBox(_T("Text Written"),IDOK,NULL);
	else
		AfxMessageBox(_T("Text not Written"),IDOK,NULL);
}
else
	AfxMessageBox(_T("Unable to Open File"),IDOK,NULL);
 
Share this answer
 
Comments
Vaibhav_J_Jaiswal 10-Apr-12 5:39am    
I got value of pApp->m_pszRegistryKey as zero which return the value of pApp->WriteProfileString() as false. Please debug that code and give me answer.
Resmi Anna 10-Apr-12 7:14am    
you can set a key which has stores the applications profile settings via the member variable m_pszRegistryKey.

eg:pApp->m_pszRegistryKey = "MYKEY"also set NULL value after usage
this key will be found under HKEY_CURRENT_USER->SOFTWARE in registry
Vaibhav_J_Jaiswal 10-Apr-12 8:49am    
It's not working. I got bResult as true but no updation is done in the ini file
Resmi Anna 10-Apr-12 9:16am    
check using the function GetProfileString() to see whether the value has been updated.

like below

CString csValue = pApp->GetProfileString(_T("General"), _T("FirstName"));

are you not getting the value "ABC" in csValue??
actually these setting details are updated in the registry.not in any INI file. You dont need to bother about viewing those details.just ensure that from program you can access it
Vaibhav_J_Jaiswal 10-Apr-12 9:26am    
I got the answer. Using WriteprofileString or GetProfileString we never update the ini file in eVC 4.0. Because these api's read the value only from the registry. For the ini file can I use any other concept. Please suggest further.
Go on "http://us.generation-nt.com/answer/read-write-ini-file-help-63453642.html" url.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900