Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read/Write INI File

39 views
Skip to first unread message

Rico Salfer

unread,
Jan 27, 2004, 3:26:04 AM1/27/04
to
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

unread,
Jan 27, 2004, 5:29:51 AM1/27/04
to
> 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

unread,
Jan 27, 2004, 7:13:32 AM1/27/04
to
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


"Rico Salfer" <anon...@discussions.microsoft.com> wrote in message
news:07B59E4F-9D0A-4AE9...@microsoft.com...


> 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
>
> ...
> }
>
>

Paul G. Tobey [eMVP]

unread,
Jan 27, 2004, 10:58:43 AM1/27/04
to
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.

"Kirk" <NO SPAM> wrote in message
news:40163db1$0$19288$626a...@news.free.fr...

veejay

unread,
Apr 16, 2012, 3:23:04 AM4/16/12
to
Rico Salfer wrote on 01/27/2004 03:26 ET :
> 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
>
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);
else
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);
else
AfxMessageBox(_T("Text not Written"),IDOK,NULL);

strValue = theApp.GetProfileString(_T("General"),
_T("FIRSTNAME"), NULL);
}
else
AfxMessageBox(_T("Unable to Open File"),IDOK,NULL);

Whenever I read or write ini file I got "bResult " as false. Please
help me to solve this.
0 new messages