CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    26

    Problem in reading INI File

    I have declared the following API in a standard module.
    Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

    My SACM.INI File is like this
    [LISTPRICE]
    Sample="LPValue"

    In form load i have written some thing like this.

    i = WritePrivateProfileString("LISTPRICE", "TRY", "100", App.Path & "\SACM.ini")

    lnglen = GetPrivateProfileString("LISTPRICE", "Sample", "", strPath, 7, App.Path & "\SACM.ini")

    msgbox strpath

    The first statement is going through fine. I am able to write into INI file.
    The second statement for reading INI file is failing. The variable strPath is showing any value.


    please help me to solve this problem.

    chakradhar

    Software Engineer
    IT Solutions India
    Banagalore

  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Problem in reading INI File

    Because the fn GetPrivateProfilestring tries to write into the memory pointed by lpString and there is no memory currently pointed by lpString.

    Also remember VB strings are not simple array of chars.

    You should modify your form_load code like this:


    i = WritePrivateProfileString("LISTPRICE", "TRY", "100", App.Path & "\SACM.ini")

    strPath = Space(256) ' Hope strpath is Dimed in the beginning!!
    lnglen = GetPrivateProfileString("LISTPRICE", "Sample", "", strPath, 256, App.Path & "\SACM.ini")
    if lnglen > 0 then
    strpath = left$(strpath, lnglen)
    end if
    msgbox strpath

    Ravi Kiran

    ps: Also, instead of "" you can use VbNullString. They say it has some performance advantages!?!


  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: Problem in reading INI File

    you didn't post the declaration of strPath.
    It needs to be dimmed accordingly as in.


    dim strPath as string * 256
    ..GetPrivateProfileString(...strPath, len(strpath)...





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured