Discussion:
Read/Write INI File
(too old to reply)
Rico Salfer
2004-01-27 08:26:04 UTC
Permalink
Hi,

I'm programming with eVC++ 4 and have the following problem:

My program should use an INI file to read and write several values. To read/write I will use the functions GetProfileString and WriteProfileString (class CWinApp). But each call of this functions failed.

I use the following code (exactly like MSDN and eVC++ helpfile) :

BOOL CMyApp::InitInstance()
{
free((void*) m_pszProfileName );
m_pszProfileName = _tcsdup(_T("/Temp/COMConn.ini"));

// SetRegistryKey("MyApp");
// LoadStdProfileSettings();
....
}

void CDlgClass::ReadIniFile()
{
CString csValue;

....
AfxGetApp()->WriteProfileString(_T("Connect"), // Section
_T("Name"), // Key
_T("MyConnect") ); // Value to write

csValue = AfxGetApp()->GetProfileString(_T("Connect"), // Section
_T("Name"), // Key
_T("Error") ); // Default

....
}


The ini file /Temp/COMConn.ini exists, but each call of WriteProfileString() returns FALSE and each call of GetProfileString() returns "Error".
Why failed every access ?

Please help me (fast).

Thank You

Rico
Kirk
2004-01-27 10:29:51 UTC
Permalink
Post by Rico Salfer
My program should use an INI file to read and write several values.
To read/write I will use the functions GetProfileString and
WriteProfileString (class CWinApp). But each call of this functions
failed.
I know that Windows CE 3.0 doesn't support ini-file functions
(GetProfileString/WriteProfileString functions reads/writes informations in
registry instead of a file). I don't know for PPC 2003.
Paul G. Tobey [eMVP]
2004-01-27 15:58:43 UTC
Permalink
It doesn't either. If you want INI files, you'll have to write the code to
write/read them yourself. You might look at the source for MFC for this; as
I recall, there's some code there that tries to do it.

Paul T.
Post by Kirk
Post by Rico Salfer
My program should use an INI file to read and write several values.
To read/write I will use the functions GetProfileString and
WriteProfileString (class CWinApp). But each call of this functions
failed.
I know that Windows CE 3.0 doesn't support ini-file functions
(GetProfileString/WriteProfileString functions reads/writes informations in
registry instead of a file). I don't know for PPC 2003.
Chris Tacke, eMVP
2004-01-27 12:13:32 UTC
Permalink
CE doesn't support the PrivateProfileString APIs. you'll have to either
find/write your own or use some other mechanism for storing settings.

-Chris
Post by Rico Salfer
Hi,
My program should use an INI file to read and write several values. To
read/write I will use the functions GetProfileString and WriteProfileString
(class CWinApp). But each call of this functions failed.
Post by Rico Salfer
BOOL CMyApp::InitInstance()
{
free((void*) m_pszProfileName );
m_pszProfileName = _tcsdup(_T("/Temp/COMConn.ini"));
// SetRegistryKey("MyApp");
// LoadStdProfileSettings();
...
}
void CDlgClass::ReadIniFile()
{
CString csValue;
...
AfxGetApp()->WriteProfileString(_T("Connect"), // Section
_T("Name"), // Key
_T("MyConnect") ); // Value to write
csValue = AfxGetApp()->GetProfileString(_T("Connect"), // Section
_T("Name"), // Key
_T("Error") ); // Default
...
}
The ini file /Temp/COMConn.ini exists, but each call of
WriteProfileString() returns FALSE and each call of GetProfileString()
returns "Error".
Post by Rico Salfer
Why failed every access ?
Please help me (fast).
Thank You
Rico
veejay
2012-04-16 07:23:04 UTC
Permalink
Rico Salfer wrote on 01/27/2004 03:26 ET
Post by Rico Salfer
Hi
I'm programming with eVC++ 4 and have the following problem
My program should use an INI file to read and write several values. T
read/write I will use the functions GetProfileString and WriteProfileStrin
(class CWinApp). But each call of this functions failed
I use the following code (exactly like MSDN and eVC++ helpfile)
BOOL CMyApp::InitInstance(
free((void*) m_pszProfileName )
m_pszProfileName = _tcsdup(_T("/Temp/COMConn.ini"))
// SetRegistryKey("MyApp")
// LoadStdProfileSettings()
void CDlgClass::ReadIniFile(
CString csValue
AfxGetApp()->WriteProfileString(_T("Connect"), // Sectio
_T("Name"), // Ke
_T("MyConnect") ); // Value to writ
csValue = AfxGetApp()->GetProfileString(_T("Connect"), // Sectio
_T("Name"), // Ke
_T("Error") ); // Defaul
The ini file /Temp/COMConn.ini exists, but each call of WriteProfileString(
returns FALSE and each call of GetProfileString() returns "Error"
Why failed every access
Please help me (fast)
Thank Yo
Ric
Hi
I got same problem

Here is my code



CString strAppIniPath = _T("")
CString strValue = _T("")

BOOL bResult = FALSE
BOOL bResult1 = FALSE

theApp.m_pszProfileName = theApp.GetAppIniPath()
strAppIniPath = theApp.GetAppIniPath()

CFile obFile

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)
els
AfxMessageBox(_T("Text not Written"),IDOK,NULL)

strValue = theApp.GetProfileString(_T("General")
_T("FIRSTNAME"), NULL)


bResult
theApp.WriteProfileString(_T("General"),_T("LastName")
_T("XYZ"))

if(bResult
AfxMessageBox(_T("Text Written"),IDOK,NULL)
els
AfxMessageBox(_T("Text not Written"),IDOK,NULL)

strValue = theApp.GetProfileString(_T("General")
_T("FIRSTNAME"), NULL)

els
AfxMessageBox(_T("Unable to Open File"),IDOK,NULL)

Whenever I read or write ini file I got "bResult " as false. Pleas
help me to solve this.

Loading...