Get data from .ini file?

I must be overlooking something really basic. I'm building a new version of an application that was using .ini files to store various data. But, when Setup installs my new version, I want to switch to using the Registry. I want Setup to read the .ini file data and copy it into the Registry.

Trouble is, I am having no luck finding a way to get VB5 to read from the .ini file! I first tried the GetSetting function, but no luck--just returns an empty string every time. Surely, there must be a way. Ideas, anyone?!
JimKirbyAsked:
Who is Participating?
 
kamallConnect With a Mentor Commented:
Here are the functions and sample code for reading/writting to INI files:

    Private 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
   
    Private 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

'Writting to the INI file:
            RetVal = WritePrivateProfileString(lpAppName$, lpKeyName$, WriteValue$, lpFileName$)

Reading from the INI file:
            RetVal = GetPrivateProfileString(lpAppName$, lpKeyName$, lpDefault$, ReturnValue$, Size&, lpFileName$)

Hope that helps.
If you have any questions, leave me a comment.
Regards.
0
 
JimKirbyAuthor Commented:
I could add a reference to MS Word, and us "system.PrivateProfileString(...)", but that seems to be a bit awkward...
   jk
0
 
kamallCommented:
BTW, the lpAppName$ is the section name. ex. Desktop.
The value of the key you read is returned in the ReturnValue$ argument.
0
 
JimKirbyAuthor Commented:
This is good stuff! I would never have thought of the API call approach. Microsoft's VB documentation was surely no help at all. Thank you!  jk
0
 
kamallCommented:
You are welcome.
Regards.
0
All Courses

From novice to tech pro — start learning today.