[DEFINE]
#If Unicode Then
  #Else
  Public Const IsUnicode As Boolean = False
  #End If

#If TemporaryMemory Then
  Public ptrTemp As Long
  #End If

#If HtmlHelp Then
  #If DoeventsEx_GetTickCount And DoeventsEx_GetElapsedTime Then
    Private HtmlHelp_LastCall As Long
    #Else
    Private HtmlHelp_Active As Boolean
    #End If
  #End If

[CODE]
Public Function ApplicationStart(Optional ByVal MaxIconSupport As Long = 0&) As Boolean
  #If ListView Then
    Dim xType1 As InitCommonControlsExType
    #End If

  #If UIntAddUInt Or UIntSubUInt Or CallFunctionFastASM Then
    Dim hProcess As Long
    #End If
  
  #If UIntAddUInt Or UIntSubUInt Or CallFunctionFastASM Then
    hProcess = OpenProcess(&H38&, 0&, GetCurrentProcessId)
    If Not hProcess = 0& Then
      #If UIntAddUInt Then
        Call UIntAddUInt_Prepare(hProcess, AddressOf UIntAddUInt)
        #End If
      #If UIntSubUInt Then
        Call UIntSubUInt_Prepare(hProcess, AddressOf UIntSubUInt)
        #End If
      #If CallFunctionFast1 Then
        Call CallFunctionFast_Prepare(hProcess, AddressOf CallFunctionFast1)
        #End If
      #If CallFunctionFast2 Then
        Call CallFunctionFast_Prepare(hProcess, AddressOf CallFunctionFast2)
        #End If
      #If CallFunctionFast3 Then
        Call CallFunctionFast_Prepare(hProcess, AddressOf CallFunctionFast3)
        #End If
      #If CallFunctionFast4 Then
        Call CallFunctionFast_Prepare(hProcess, AddressOf CallFunctionFast4)
        #End If
      #If CallFunctionFast5 Then
        Call CallFunctionFast_Prepare(hProcess, AddressOf CallFunctionFast5)
        #End If
      Call CloseHandle(hProcess)
      End If
    #End If

  #If asm_ctCompressA_Decompress Then
    If Not CreateCodeFromHexAssembly(ctCompressA_Decompress_Exe, ctCompressA_Decompress_Mem, ctCompressA_Decompress_Bin) Then Goto AssemblyFailed
    #End If
  #If asm_StrStrW_CrLf Then
    If Not CreateCodeFromHexAssembly(StrStrW_CrLf_Exe, StrStrW_CrLf_Mem, StrStrW_CrLf_Bin) Then Goto AssemblyFailed
    #End If

  #If TemporaryMemory Then
    If ptrTemp = 0& Then
      ptrTemp = LocalAlloc(0&, ptrTempSize)
      If Not ptrTemp = 0& Then
        ApplicationStart = True
        End If
      End If
    #Else
    ApplicationStart = True
    #End If

  #If CreateCodeFromHexAssembly Then
AssemblyFailed:
    #End If
  
  #If ListView Then
    xType1.dwSize = 8&
    xType1.dwICC = &H1& 'listview
    Call InitCommonControlsEx(xType1)
    #End If
  
  #If ToolTip Then
    Set ToolTip_Collection = New Collection
    #If ToolTip_SetEnable Then
      ToolTip_IsEnabled = True
      #End If
    #If GetAPIPopupMenu Then
      ToolTip_IsEnabledInt = True
      #End If
    #End If
  #If OSVersionDependent Then
    #If LoadResEx_Icon_Shared Then
      Call OSVersionDependent(MaxIconSupport)
      #Else
      Call OSVersionDependent()
      #End If
    #End If
  #If LoadResEx_SetLanguageFile Then
    LoadResEx_LanguageFile_hModule = App.hInstance
    #End If
  #If LoadResEx_SetThemeFile Then
    LoadResEx_ThemeFile_hModule = App.hInstance
    #End If
  #If XPTheme_Auto Then
    Call UpdateTheme
    #End If
  #If CreateAssemblyFromHexString Then
    Call CreateAssembliesFromHexString
    #End If
  End Function

Public Sub ApplicationClose()
  #If asm_ctCompressA_Decompress Then
    If Not ctCompressA_Decompress_Mem = 0& Then Call VirtualFree(ctCompressA_Decompress_Mem, 0&, &H8000&)
    ctCompressA_Decompress_Mem = 0&
    #End If
  #If asm_StrStrW_CrLf Then
    If Not StrStrW_CrLf_Mem = 0& Then Call VirtualFree(StrStrW_CrLf_Mem, 0&, &H8000&)
    StrStrW_CrLf_Mem = 0&
    #End If
  #If GDIPlus Then
    If Not GDIPlus_Count = 0& Then
      Call GdiplusShutdown(GDIPlus_Token)
      End If
    #End If
  #If TaskbarProgress Then
    Call TaskbarProgress_Close()
    #End If
  #If XPTheme_Auto Then
    Call UnTheme()
    #End If

  #If HtmlHelp Then
#If DoeventsEx_GetTickCount And DoeventsEx_GetElapsedTime Then
    If Not HtmlHelp_LastCall = 0& Then
#Else
    If HtmlHelp_Active Then
#End If
      Call HtmlHelp(0&, 0&, &h12&, 0&)
      End If
    #End If
  #If TemporaryMemory Then
    If Not ptrTemp = 0& Then
      Call LocalFree(ptrTemp)
      ptrTemp = 0&
      End If
    #End If
  End Sub
