Registry and INI files

When you load your 16-bit Visual Basic 4 program that uses GetSettings and SaveSettings into Visual Basic 5, you might wonder where your INI file
values have gone. They are now stored under the Registry entry called HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appName\ section, which would contain an entry such as key: REG_SZ: value. These keys and values can be created and modified by running RegEdit under Windows 95 and Regedt32 under Windows NT.

Replacing calls to the Windows API to manipulate INI file settings with the Visual Basic Settings functions can cause odd effects. Any 32-bit Visual Basic application will automatically look in the Registry for configuration information. To get around these calls when replacing a 16-bit Visual Basic 3 or Visual Basic 4 program with a 32-bit one, subclass the stock Visual Basic 5 GetSettings with the following:

#If Win32 Then
    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
#End If

    Public Function GetSetting(ByVal Appname As String, _
        ByVal Section As String, ByVal Key As String, _
        ByVal Default As String) As String
    ' This function uses the program’s INI file
    ' and copies its values to the Registry.
    Dim sValue As String
#If Win16 Then
    GetSetting = VBA.GetSetting(Appname, Section, Key, Default)
#Else

    lRet = GetPrivateProfileString(Section, Key, Default, _
        sValue, nSize, Appname)
    Call SaveSetting(Appname, Section, Key, sValue)
#End If

Additionally, you might have to run applications in a mixed Visual Basic 3 or 16-bit Visual Basic 4 environment when porting a suite of programs to 32-bit versions over a period of time. This means that you might need to update both the Registry and the INI files. Again, you can do this by subclassing the GetSettings function and the SaveSettings function. Either replace GetSettings or write code that updates both the Registry and the INI file entries.