[API]
LocalAlloc
LocalFree

[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&
#If Unicode Then
  #Else
  Public Const IsUnicode as Boolean = False
  #End If

[CODE]
#If LoadResEx_IconStuff Then
Public Function ApplicationStart(Optional ByVal MaxIconSupport As Long = 0&) As Boolean
#Else
Public Function ApplicationStart() As Boolean
#End If

  #If Unicode Or LoadResEx_IconStuff Then
    Dim xType1 As OSVERSIONINFO
    #End If
  #If XPTheme_DefControls Or LoadResEx_IconStuff Then
    Dim xLong1 As Long
    #End If

  If ptrTemp = 0& Then
    ptrTemp = LocalAlloc(0&, ptrTempSize)
    If Not ptrTemp = 0& Then
      ApplicationStart = True
      #If XPTheme_DefControls Then
        xLong1 = LoadLibraryA("shell32.dll")
        Call InitCommonControls
        Call FreeLibrary(xLong1)
        #End If

      #If LoadResEx_SetLanguageFile Then
        LoadResEx_LanguageFile_hModule = App.hInstance
        #End If

       #If LoadResEx_IconStuff Then
        xType1.dwOSVersionInfoSize = 148&
        If Not GetVersionExA(xType1) = 0& Then
#If DoEventsEx_Sleep Then
          DoEventsEx_Sleep_WaitableTimers = (xType1.dwPlatformId = &H2&) Or (xType1.dwMajorVersion > 4&) Or (xType1.dwMajorVersion = 4& And xType1.dwMinorVersion >= 10&)
#End If
          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
                  '#If Unicode Then
                  '  IsUnicode = True
                  '  #End If
                  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
                  '#If Unicode Then
                  '  IsUnicode = True
                  '  #End If
                  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
                #If Unicode Then
                  IsUnicode = True
                  #End If
                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
#If Unicode Then
            ElseIf (xType1.dwPlatformId = &H2&) Then
            IsUnicode = True
#End If
            End If
          End If
        #ElseIf Unicode Then
        xType1.dwOSVersionInfoSize = 148&
        If Not GetVersionExA(xType1) = 0& Then
          IsUnicode = (xType1.dwPlatformId = &H2&)
#If DoEventsEx_Sleep Then
          DoEventsEx_Sleep_WaitableTimers = (xType1.dwPlatformId = &H2&) Or (xType1.dwMajorVersion > 4&) Or (xType1.dwMajorVersion = 4& And xType1.dwMinorVersion >= 10&)
#End If
          End If
        #ElseIf DoEventsEx_Sleep Then
        DoEventsEx_Sleep_WaitableTimers = (xType1.dwPlatformId = &H2&) Or (xType1.dwMajorVersion > 4&) Or (xType1.dwMajorVersion = 4& And xType1.dwMinorVersion >= 10&)
        #End If
      #If XPTheme_Auto Then
        Call UpdateTheme()
        #End If
      End If
    #If CreateAssemblyFromHexString Then
      Call CreateAssembliesFromHexString()
      #End If
    End If
  End Function

Public Sub ApplicationClose()
  #If XPTheme_Auto Then
    Call UnTheme()
    #End If
  Call LocalFree(ptrTemp)
  End Sub
