Can't get "GetPrivateProfileString" to work? 
Author Message
 Can't get "GetPrivateProfileString" to work?

Hello all,

    I would like to have a private .ini file that would be part of my
executable, and I don't want
to use the Registry.  So I'm trying :

  LPCTSTR lpAppName = "[section]";       // section name
  LPCTSTR lpKeyName = "key = ";          // key name
  LPCTSTR lpString = "section one";          // string to add
  LPCTSTR lpFileName = AfxGetAppName();  // initialization file

  ///Write the info
  BOOL bRtrn =
WritePrivateProfileString(lpAppName,lpKeyName,lpString,lpFileName);

  LPCTSTR lpDefault = "xxx";        // default string
  char lpReturnedString[64];           // destination buffer
  DWORD nSize = 64;                   // size of destination buffer

  ///Read back the info
  DWORD nRtrn = GetPrivateProfileString(lpAppName,lpKeyName,lpDefault,
                             lpReturnedString,nSize,lpFileName);

  Unfortunately I always get back the default string....what am I not doing
correctly?

  TIA,

  Ray K.



Sat, 25 Oct 2003 19:37:14 GMT  
 Can't get "GetPrivateProfileString" to work?
rayk!

You'll need neither the brackets, nor the equal sign: "section" and "key" is
what you want for the section and key respectively. A minor nitpick is that
you are using the application name as the ini-file name, but you
could/should also qualify with the desired directory, to avoid cluttering
the Windows directory with INI-files (well, a minor hangup of mine).

And why bother saving the return value from the write function, if you are
not checking it? {*filter*}, {*filter*}!

Johan Rosengren
Responsable Informatique
PACTA S.A.


Quote:
> Hello all,

>     I would like to have a private .ini file that would be part of my
> executable, and I don't want
> to use the Registry.  So I'm trying :

>   LPCTSTR lpAppName = "[section]";       // section name
>   LPCTSTR lpKeyName = "key = ";          // key name
>   LPCTSTR lpString = "section one";          // string to add
>   LPCTSTR lpFileName = AfxGetAppName();  // initialization file

>   ///Write the info
>   BOOL bRtrn =
> WritePrivateProfileString(lpAppName,lpKeyName,lpString,lpFileName);

>   LPCTSTR lpDefault = "xxx";        // default string
>   char lpReturnedString[64];           // destination buffer
>   DWORD nSize = 64;                   // size of destination buffer

>   ///Read back the info
>   DWORD nRtrn = GetPrivateProfileString(lpAppName,lpKeyName,lpDefault,
>                              lpReturnedString,nSize,lpFileName);

>   Unfortunately I always get back the default string....what am I not
doing
> correctly?

>   TIA,

>   Ray K.



Sat, 25 Oct 2003 20:18:22 GMT  
 Can't get "GetPrivateProfileString" to work?
Hello Johan,

     Thanks for the response...and no I am not being "..{*filter*}, {*filter*}!";
after I figure out how
to make the functions work I will be checking/using the return values, I
just didn't want to send
a longer post than necessary.
     However, "..to avoid cluttering  the Windows directory with
INI-files..." is exactly what I'm trying to do, but have not had any success
with making this INI file a part of my executable and not
a part of Windows; this is why I'm trying to get  Write/Get 'Private'
Profile string to work!
    If you have any suggestions as to how to do this, I would apprecitate
hearing from you?


Quote:
> rayk!

> You'll need neither the brackets, nor the equal sign: "section" and "key"
is
> what you want for the section and key respectively. A minor nitpick is
that
> you are using the application name as the ini-file name, but you
> could/should also qualify with the desired directory, to avoid cluttering
> the Windows directory with INI-files (well, a minor hangup of mine).

> And why bother saving the return value from the write function, if you are
> not checking it? {*filter*}, {*filter*}!

> Johan Rosengren
> Responsable Informatique
> PACTA S.A.



> > Hello all,

> >     I would like to have a private .ini file that would be part of my
> > executable, and I don't want
> > to use the Registry.  So I'm trying :

> >   LPCTSTR lpAppName = "[section]";       // section name
> >   LPCTSTR lpKeyName = "key = ";          // key name
> >   LPCTSTR lpString = "section one";          // string to add
> >   LPCTSTR lpFileName = AfxGetAppName();  // initialization file

> >   ///Write the info
> >   BOOL bRtrn =
> > WritePrivateProfileString(lpAppName,lpKeyName,lpString,lpFileName);

> >   LPCTSTR lpDefault = "xxx";        // default string
> >   char lpReturnedString[64];           // destination buffer
> >   DWORD nSize = 64;                   // size of destination buffer

> >   ///Read back the info
> >   DWORD nRtrn = GetPrivateProfileString(lpAppName,lpKeyName,lpDefault,
> >                              lpReturnedString,nSize,lpFileName);

> >   Unfortunately I always get back the default string....what am I not
> doing
> > correctly?

> >   TIA,

> >   Ray K.



Sat, 25 Oct 2003 20:55:08 GMT  
 Can't get "GetPrivateProfileString" to work?
Lose the section name brackets in the search (but keep them in the INI file
:-)  ). The brackets are "assumed" when searching for the sections. If you
include them, it will likely look for "[[section]]"
e.g.
LPCTSTR lpAppName = "section";       // section name

This should work fine (always has for me, except on Windows CE; where they
are not supported).

Greg


Quote:
> Hello all,

>     I would like to have a private .ini file that would be part of my
> executable, and I don't want
> to use the Registry.  So I'm trying :

>   LPCTSTR lpAppName = "[section]";       // section name
>   LPCTSTR lpKeyName = "key = ";          // key name
>   LPCTSTR lpString = "section one";          // string to add
>   LPCTSTR lpFileName = AfxGetAppName();  // initialization file

>   ///Write the info
>   BOOL bRtrn =
> WritePrivateProfileString(lpAppName,lpKeyName,lpString,lpFileName);

>   LPCTSTR lpDefault = "xxx";        // default string
>   char lpReturnedString[64];           // destination buffer
>   DWORD nSize = 64;                   // size of destination buffer

>   ///Read back the info
>   DWORD nRtrn = GetPrivateProfileString(lpAppName,lpKeyName,lpDefault,
>                              lpReturnedString,nSize,lpFileName);

>   Unfortunately I always get back the default string....what am I not
doing
> correctly?

>   TIA,

>   Ray K.



Sat, 25 Oct 2003 23:58:54 GMT  
 Can't get "GetPrivateProfileString" to work?
Don't use brackets in the section name and no equal sign in the key name.


Quote:
> Hello all,

>     I would like to have a private .ini file that would be part of my
> executable, and I don't want
> to use the Registry.  So I'm trying :

>   LPCTSTR lpAppName = "[section]";       // section name
>   LPCTSTR lpKeyName = "key = ";          // key name
>   LPCTSTR lpString = "section one";          // string to add
>   LPCTSTR lpFileName = AfxGetAppName();  // initialization file

>   ///Write the info
>   BOOL bRtrn =
> WritePrivateProfileString(lpAppName,lpKeyName,lpString,lpFileName);

>   LPCTSTR lpDefault = "xxx";        // default string
>   char lpReturnedString[64];           // destination buffer
>   DWORD nSize = 64;                   // size of destination buffer

>   ///Read back the info
>   DWORD nRtrn = GetPrivateProfileString(lpAppName,lpKeyName,lpDefault,
>                              lpReturnedString,nSize,lpFileName);

>   Unfortunately I always get back the default string....what am I not
doing
> correctly?

>   TIA,

>   Ray K.



Sun, 26 Oct 2003 20:30:12 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Help with compiling a "canned" program

2. Displaying binary data as ascii "1"'s and "0"'s

3. Displaying binary data as ascii "1"'s and "0"'s

4. '.', '::", "->"

5. My "C" variables don't work with "C++"?

6. why CFile::Write doesn't work for "\n" and "\r"?

7. Why CFile::Write doesn't work for "\n" and "\r"?

8. 250 times 'fopen(...,"a")':errno 24

9. Problem getting "memory cannot be read"

10. getting #define value from its "name"

11. v05i053: A "safe" replacement for gets()

12. "Apply" gets called twice

 

 
Powered by phpBB® Forum Software