Problem with Win API function GetPrivateProfileString. 
Author Message
 Problem with Win API function GetPrivateProfileString.

I am using Win 32 API function.

    Dim buffer As String
    section, key,  INFILE, DefaultFind all of these are string.
GetPrivateProfileString(section, key, DefaultFind, buffer, 80, INIFILE)

VB is crashing right after this statement. After some research I found out
that "buffer" is the problem.
When I pass buffer as VarPtr(buffer) VB did not crash but I did not got the
Value.

 How to solve this Problem?
Thanks
Trupti



Fri, 21 Mar 2003 03:00:00 GMT  
 Problem with Win API function GetPrivateProfileString.

Quote:
> I am using Win 32 API function.

>     Dim buffer As String
>     section, key,  INFILE, DefaultFind all of these are string.
> GetPrivateProfileString(section, key, DefaultFind, buffer, 80, INIFILE)

> VB is crashing right after this statement. After some research I found out
> that "buffer" is the problem.
> When I pass buffer as VarPtr(buffer) VB did not crash but I did not got the
> Value.

>  How to solve this Problem?
> Thanks
> Trupti

Trupti,

Use Dim buffer as String * 80 instead.

Regards, Hugo.



Sat, 22 Mar 2003 13:39:55 GMT  
 Problem with Win API function GetPrivateProfileString.
Long ago there was an error in the API Viewer with the declaration of
GetPrivateProfileString,

Check the declaration with ie. MSDN


Quote:
> I am using Win 32 API function.

>     Dim buffer As String
>     section, key,  INFILE, DefaultFind all of these are string.
> GetPrivateProfileString(section, key, DefaultFind, buffer, 80, INIFILE)

> VB is crashing right after this statement. After some research I found out
> that "buffer" is the problem.
> When I pass buffer as VarPtr(buffer) VB did not crash but I did not got
the
> Value.

>  How to solve this Problem?
> Thanks
> Trupti



Sun, 23 Mar 2003 03:00:00 GMT  
 Problem with Win API function GetPrivateProfileString.

Hi Trupti

This is the function I use to retrieve a string from an INI file.
This has been working for some time and never had any
problems with it.

Private Function GetProfileString(ByVal v_sSectionName As String, _
                                  ByVal v_sKeyName As String, _
                                  ByVal v_sIniFileName As String, _
                                  ByRef r_sReturnedStr As String) As Long

   Dim lSize As Long

   lSize = 256
   GetProfileString = 0
   r_sReturnedStr = ""

   lSize = GetPrivateProfileString(v_sSectionName, _
                                   v_sKeyName, _
                                   "", _
                                   r_sReturnedStr, _
                                   lSize, _
                                   v_sIniFileName) + 2

   If (CBool(lSize - 2)) Then
      '// Fill the returned string variable with spaces
      r_sReturnedStr = Space$(lSize)

      '// Read the actual string...
      lSize = GetPrivateProfileString(v_sSectionName, _
                                      v_sKeyName, _
                                      "", _
                                      r_sReturnedStr, _
                                      lSize, _
                                      v_sIniFileName)

      r_sReturnedStr = Left$(r_sReturnedStr, lSize)
      GetProfileString = lSize
   End If

End Function

There you go.

--


Quote:
> I am using Win 32 API function.

>     Dim buffer As String
>     section, key,  INFILE, DefaultFind all of these are string.
> GetPrivateProfileString(section, key, DefaultFind, buffer, 80, INIFILE)

> VB is crashing right after this statement. After some research I found out
> that "buffer" is the problem.
> When I pass buffer as VarPtr(buffer) VB did not crash but I did not got
the
> Value.

>  How to solve this Problem?
> Thanks
> Trupti



Mon, 24 Mar 2003 03:00:00 GMT  
 Problem with Win API function GetPrivateProfileString.

PMFJI, but why are you calling the API function twice??


Quote:
> Hi Trupti

> This is the function I use to retrieve a string from an INI file.
> This has been working for some time and never had any
> problems with it.

> Private Function GetProfileString(ByVal v_sSectionName As String, _
>                                   ByVal v_sKeyName As String, _
>                                   ByVal v_sIniFileName As String, _
>                                   ByRef r_sReturnedStr As String) As Long

>    Dim lSize As Long

>    lSize = 256
>    GetProfileString = 0
>    r_sReturnedStr = ""

>    lSize = GetPrivateProfileString(v_sSectionName, _
>                                    v_sKeyName, _
>                                    "", _
>                                    r_sReturnedStr, _
>                                    lSize, _
>                                    v_sIniFileName) + 2

>    If (CBool(lSize - 2)) Then
>       '// Fill the returned string variable with spaces
>       r_sReturnedStr = Space$(lSize)

>       '// Read the actual string...
>       lSize = GetPrivateProfileString(v_sSectionName, _
>                                       v_sKeyName, _
>                                       "", _
>                                       r_sReturnedStr, _
>                                       lSize, _
>                                       v_sIniFileName)

>       r_sReturnedStr = Left$(r_sReturnedStr, lSize)
>       GetProfileString = lSize
>    End If

> End Function

> There you go.

> --



> > I am using Win 32 API function.

> >     Dim buffer As String
> >     section, key,  INFILE, DefaultFind all of these are string.
> > GetPrivateProfileString(section, key, DefaultFind, buffer, 80, INIFILE)

> > VB is crashing right after this statement. After some research I found
out
> > that "buffer" is the problem.
> > When I pass buffer as VarPtr(buffer) VB did not crash but I did not got
> the
> > Value.

> >  How to solve this Problem?
> > Thanks
> > Trupti



Fri, 04 Apr 2003 03:00:00 GMT  
 Problem with Win API function GetPrivateProfileString.

Most likely, the first pass captures the size of the data that will be
returned in the second pass.

- M2CW


Quote:
> PMFJI, but why are you calling the API function twice??



> > Hi Trupti

> > This is the function I use to retrieve a string from an INI file.
> > This has been working for some time and never had any
> > problems with it.

> > Private Function GetProfileString(ByVal v_sSectionName As String, _
> >                                   ByVal v_sKeyName As String, _
> >                                   ByVal v_sIniFileName As String, _
> >                                   ByRef r_sReturnedStr As String) As
Long

> >    Dim lSize As Long

> >    lSize = 256
> >    GetProfileString = 0
> >    r_sReturnedStr = ""

> >    lSize = GetPrivateProfileString(v_sSectionName, _
> >                                    v_sKeyName, _
> >                                    "", _
> >                                    r_sReturnedStr, _
> >                                    lSize, _
> >                                    v_sIniFileName) + 2

> >    If (CBool(lSize - 2)) Then
> >       '// Fill the returned string variable with spaces
> >       r_sReturnedStr = Space$(lSize)

> >       '// Read the actual string...
> >       lSize = GetPrivateProfileString(v_sSectionName, _
> >                                       v_sKeyName, _
> >                                       "", _
> >                                       r_sReturnedStr, _
> >                                       lSize, _
> >                                       v_sIniFileName)

> >       r_sReturnedStr = Left$(r_sReturnedStr, lSize)
> >       GetProfileString = lSize
> >    End If

> > End Function

> > There you go.

> > --



> > > I am using Win 32 API function.

> > >     Dim buffer As String
> > >     section, key,  INFILE, DefaultFind all of these are string.
> > > GetPrivateProfileString(section, key, DefaultFind, buffer, 80,
INIFILE)

> > > VB is crashing right after this statement. After some research I found
> out
> > > that "buffer" is the problem.
> > > When I pass buffer as VarPtr(buffer) VB did not crash but I did not
got
> > the
> > > Value.

> > >  How to solve this Problem?
> > > Thanks
> > > Trupti



Sun, 06 Apr 2003 03:00:00 GMT  
 Problem with Win API function GetPrivateProfileString.
On Wed, 18 Oct 2000 19:14:46 -0400, "James M. Parker"

Quote:

>Most likely, the first pass captures the size of the data that will be
>returned in the second pass.

Not nessecary

Public Function GetProf(ByVal section As String, ByVal variable As
String, ByVal iniFile As String) As String
Dim buf As String
buf = Space(64) ' its an ini entry not a paperback novel
Dim mA As Integer
mA = GetPrivateProfileString(section & Chr$(0), variable & Chr$(0),
Chr$(0), buf$, Len(buf$), iniFile & Chr$(0))
GetProf = Left$(buf$, mA)
End Function

works fine



Mon, 07 Apr 2003 11:38:02 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Problem with Win API function GetPrivateProfileString.

2. Win API: GetPrivateProfileString

3. problems with _lwrite (Win-API-function)

4. Does anyone haver a working sample of API function GetPrivateProfileString which reads values from ini files

5. Does anyone haver a working sample of API function GetPrivateProfileString which reads values from ini files

6. problems with _lwrite (Win-API-function)

7. Problem with the CheckMenuRadioItem WIN API function....

8. Problems with CreateDirectory WIN API function...

9. WIN 2k API vs WIN 98/WIN NT API - Help needed

10. Win API functions that don't seem to exist in Win32 API

11. API: GetPrivateProfileString Problem

12. Problem with GetPrivateProfileString API

 

 
Powered by phpBB® Forum Software