Converting 16-bit API Calls

Migrating to Microsoft Excel 97 implies that you are running a 32-bit operating system. If your application was designed for a 16-bit operating system and makes use of 16-bit Windows API calls, these calls will have to be converted to 32-bit calls. An application with adequate error handling may mask calls to the incorrect API, so you should check that all your API calls are "wrapped" to make them operating system independent.

The following routine checks the operating system version and sets a variable to identify it. The second routine uses the OSBitness variable to call the appropriate API:

Function OSBitness() As Integer
    If InStr(Application.OperatingSystem, "32") > 0 Then
        OSBitness = 32
    Else         'default is 16 bit
        OSBitness = 16
    End If
End Function

Sub ReadIni()
If OSBitness = 16 Then
        nReturn = GetPrivateProfileString16("Reports", "ReportNumberSelected", "", sGetINIValue, 255, sINIFile)
Else
    nReturn = GetPrivateProfileString32("Reports", _
        "ReportNumberSelected", "", sGetINIValue, 255, sINIFile)
    gnReportNumSelected = Val(Left$(sGetINIValue, nReturn))
End Sub

For more information about the Win32 API and migrating from 16-bit to 32-bit, see "Calling the Win32 API" in Porting Your 16-Bit Microsoft Office-Based Solutions to 32-Bit Microsoft Office, at http://www.microsoft.com/officedev/techinfo/porting.htm#Calling.