[API]

[DEFINE]
Public ptrTemp As Long
Private Const ptrTempSize As Long = 32000 ' int (signed?), so crashes with some apis
Public Const ptrTempSizeX As Long = ptrTempSize - 1&
Public Const ptrTempSizeXW As Long = (ptrTempSize \ 2&) - 1&

[CODE]
#If LoadResEx_IconStuff Then
Public Function ApplicationStart(Optional ByVal MaxIconSupport As Long = 0&) As Boolean
  Dim xType1 As OSVERSIONINFO
  Dim xLong1 As Long

  If ptrTemp = 0& Then
#Else
Public Function ApplicationStart() As Boolean
#End If
  
    ptrTemp = LocalAlloc(0&, ptrTempSize)

#If LoadResEx_LanguageFile Then
    LoadResEx_LanguageFile_hModul = App.hInstance
#End If

#If LoadResEx_IconStuff Then
    xType1.dwOSVersionInfoSize = 148&
    If Not GetVersionExA(xType1) = 0& Then
  
      If MaxIconSupport > 0& Then
        xLong1 = GetDC(0&)
        If Not xLong1 = 0& Then
          LoadResEx_IsHighColor = (GetDeviceCaps(xLong1, 12&) > 15&)
          Call ReleaseDC(0&, xLong1)
        
          If (xType1.dwPlatformId = &H2&) Then
            'nt series
            '2003=5.2
            If xType1.dwMajorVersion > 5& Or xType1.dwMajorVersion = 5& And xType1.dwMinorVersion > 1& Then
              If LoadResEx_IsHighColor Then
                LoadResex_Caps_WinDIcon = LoadResEx_IconOS_WinVista
                Else
                LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win2000ME_16Color 'LoadResEx_IconOS_WinVista_16Color
                End If
              LoadResex_Caps_TrayIcon = LoadResex_Caps_WinDIcon
              'IsUnicode = True
              ElseIf xType1.dwMajorVersion = 5& Then
              If xType1.dwMinorVersion >= 1& Then
                If LoadResEx_IsHighColor Then
                  LoadResex_Caps_WinDIcon = LoadResEx_IconOS_WinXP
                  Else
                  LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win2000ME_16Color
                  End If
                LoadResex_Caps_TrayIcon = LoadResex_Caps_WinDIcon
                Else
                If LoadResEx_IsHighColor Then
                  LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win2000ME
                  Else
                  LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win2000ME_16Color
                  End If
                LoadResex_Caps_TrayIcon = LoadResEx_IconOS_Win2000ME_16Color
                End If
              'IsUnicode = True
              Else
              If LoadResEx_IsHighColor Then
                LoadResex_Caps_WinDIcon = LoadResEx_IconOS_WinNT
                'Else
                'LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win95_16Color
                End If
              'LoadResex_Caps_TrayIcon = LoadResEx_IconOS_Win95_16Color
              End If
            IsUnicode = True
            Else
            If xType1.dwMajorVersion > 4& Or xType1.dwMajorVersion = 4& And xType1.dwMinorVersion >= 90& Then
              If LoadResEx_IsHighColor Then
                LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win2000ME
                Else
                LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win2000ME_16Color
                End If
              LoadResex_Caps_TrayIcon = LoadResex_Caps_WinDIcon
              ElseIf xType1.dwMajorVersion = 4& And xType1.dwMinorVersion >= 10& Then
              If LoadResEx_IsHighColor Then
                LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win98
                'Else
                'LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win95_16Color
                End If
              'LoadResex_Caps_TrayIcon = LoadResEx_IconOS_Win95_16Color
              Else
              If LoadResEx_IsHighColor Then
                LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win95
                'Else
                'LoadResex_Caps_WinDIcon = LoadResEx_IconOS_Win95_16Color
                End If
              'LoadResex_Caps_TrayIcon = LoadResEx_IconOS_Win95_16Color
              End If
            End If
          End If
        If LoadResex_Caps_WinDIcon > MaxIconSupport Then
          LoadResex_Caps_WinDIcon = MaxIconSupport
          If LoadResex_Caps_TrayIcon > MaxIconSupport Then LoadResex_Caps_TrayIcon = MaxIconSupport
          End If
        'If ForceHiColorTrayIcons Then LoadResex_Caps_TrayIcon = LoadResex_Caps_WinDIcon
        ElseIf (xType1.dwPlatformId = &H2&) Then
        IsUnicode = True
        End If
      End If
    End If
#End If
  End Function

Public Function ApplicationClose()
  Call LocalFree(ptrTemp)
  End Function
