Attribute VB_Name = "Common"
Option Explicit
Option Base 0

' This file was generated by LibBuild, based on code snippets copyright (C) by Jan
' Vorel. If you want to use parts of this code, check for LibBuild on
' http://www.ctuser.net , which is published under the GNU General Public License.
' Please note that this file is generated on demand and may contain additional or
' modified content. If the project using this file is NOT copyright by Jan Vorel,
' or NOT published under the GNU General Public License, you may NOT use any part.

' The sorting code is an adjusted ShellSort code.
' If you use this adjusted code, or work based on this adjusted code, you are
' bound to a valid license of the author of that adjusted code. The author of that
' adjusted code does not claim any copyright on the algorithm itself.

#Const LoadResEx_Dialog_ListFill_ExtendedUI = True
#Const SetIsMinWindows2000W = True
#Const SetIsMinWindowsXP = True
#Const LoadResEx_PagedDialog_NoContextHelpHook = True
#Const ctSSLayer_LoadSongAbort = True
#Const ctSSLayer_LoadSongFinished = True
#Const ctSSLayer_GetInfoString = True
#Const ctSSLayer_GetPosition = True
#Const ctSSLayer_SeekSong = True
#Const ctSSLayer_SetPause = True
#Const ctSSLayer_SetVolume = True
#Const ctSSLayer_GetSongLength = True
#Const ctSSLayer_RefreshDeviceList = True
#Const ctSSLayer_MusicGetPattern = True
#Const ctSSLayer_MusicGetPatterns = True
#Const ctSSLayer_MusicHasFinished = True
#Const ctSSLayer_MusicTime = True
#Const ctSSLayer_Spectrum = True
#Const ctSSLayer_SetEndCallback = True
#Const ctSSLayer_UpdateCDDA = True
#Const ctSSLayer_UpdateLooping = True
#Const ctSSLayer_UpdatePanning = True
#Const HyperlinkList_UseIcons = True
#Const SetHyperLinkList_InfoDialog_CustomHListID = True
#Const SetHyperLinkList_InfoDialog_CustomFocusID = True
#Const SetIsMinWindows982000 = True

#Const Application = True
#Const ArraySort_String_IgnoreCase = True
#Const ArraySort_String_StartPos_IgnoreCase = True
#Const CallFunction_Fast = True
#Const CallFunction_Indirect = True
#Const GetOpenFileName = True
#Const GetOpenFileName_MultiDataString = True
#Const GetSaveFileName = True
#Const CommonDLG_OpenPath = True
#Const CreateDialogIndirectParam = True
#Const CreateDirectoryEx = True
#Const CreateFontIndirect = True
#Const CreateFontIndirectEx = True
#Const ctSSLayer = True
#Const ctSSLayer_Devices = True
#Const ctSSLayer_Misc = True
#Const ctSSLayer_Music = True
#Const ctSSLayer_ReadSongInfo = True
#Const DoEventsEx_GetElapsedTime = True
#Const DoEventsEx_GetTickCount = True
#Const DoEventsEx = True
#Const DoEventsEx_SleepPeriodical = True
#Const DragQueryFile = True
#Const DrawText = True
#Const FindFirstChangeNotification = True
#Const FindFirstFile = True
#Const FindWindow = True
#Const GetAddressOf = True
#Const GetAPIPopupMenu = True
#Const GetDlgItemText = True
#Const GetFileVersionField = True
#Const GetFileAttributes = True
#Const GetFullPathName = True
#Const GetKeyNameText = True
#Const GetSpecialFolderPath = True
#Const GetStrippedCommandLine = True
#Const GetTextOutWidth = True
#Const GetWindowLong = True
#Const GetWindowText = True
#Const LoadLibrary = True
#Const LoadResEx_Data = True
#Const LoadResEx_Dialog = True
#Const LoadResEx_PagedDialog = True
#Const LoadResEx_Dialog_Enable = True
#Const LoadResEx_Dialog_SpinnerHelper = True
#Const LoadResEx_Dialog_ListHelper = True
#Const LoadResEx_Dialog_CheckBool = True
#Const LoadResEx_Menu = True
#Const LoadResEx_Menu_Add = True
#Const LoadResEx_Menu_AddSeperator = True
#Const LoadResEx_Menu_GetCaption = True
#Const LoadResEx_Menu_MakePopupMenu = True
#Const LoadResEx_Menu_SetCaption = True
#Const LoadResEx_Icon = True
#Const LoadResEx_SetLanguageFile = True
#Const LoadResEx_SetThemeFile = True
#Const LoadResEx_String = True
#Const LoadResEx_WindowIcon = True
#Const MapVirtualKey = True
#Const PeekL = True
#Const PeekS = True
#Const PeekS_Ansi = True
#Const PeekS_Wide = True
#Const PokeS = True
#Const RegCreateKeyEx = True
#Const RegDeleteKey = True
#Const RegDeleteValue = True
#Const RegEnumKey = True
#Const RegisterClassEx = True
#Const RegisterFileTypes_GetRegistered = True
#Const RegisterFileTypes_RemoveRegistered = True
#Const RegisterFileTypes_SetRegistered = True
#Const RegOpenKeyEx = True
#Const RegQueryValueEx_String = True
#Const RegSetValueEx_String = True
#Const RemovableDevices_RegisterAll = True
#Const RemovableDevices_UnregisterAll = True
#Const RemovableDevices_ResolveDriveID = True
#Const SetDlgItemText = True
#Const ShellExecute = True
#Const Shell_NotifyIcon = True
#Const SHFileOperation = True
#Const ShutdownWindowsEx = True
#Const SendMessage_String = True
#Const SetWindowLong = True
#Const SetWindowText = True
#Const TextOut = True
#Const TrackListBox = True
#Const TxtFile_ReadLine = True
#Const TxtFile_GetEncoding = True
#Const TxtFile_SetEncoding = True
#Const TxtFile_WriteCreate = True
#Const TxtFile_WriteCreateEx = True
#Const TxtFile_WriteLine = True
#Const TxtFile_WriteAppend = True
#Const URLEncode = True
#Const URLDecode = True
#Const Unicode = True
#Const WinHelp = True
#Const HtmlHelp = True
#Const GetTimeFormatNow = True
#Const DoEventsEx_IsTickCountElapsed = True
#Const UIntAddUInt = True
#Const Ellipsis_PathSmartStart = True
#Const HyperLinkList_InfoDialog = True
#Const PokeL = True
#Const CallFunction = True
#Const OPENFILENAME = True
#Const FormatMessage = True
#Const LocalAllocFromString_Wide = True
#Const LocalAllocFromString = True
#Const TemporaryMemory = True
#Const GetClassName = True
#Const DoEventsEx_Sleep = True
#Const CreateWindowEx = True
#Const GetOptMonitorFromPoint = True
#Const PostMessage = True
#Const SendMessage = True
#Const WindowToCursorPos = True
#Const DialogBoxIndirectParam = True
#Const LoadResEx_Icon_Shared = True
#Const LoadResEx_StringEx = True
#Const RemovableDevices_Register = True
#Const RemovableDevices_Unregister = True
#Const AquirePrivilege = True
#Const CreateCodeFromHexAssembly = True
#Const UIntSubUInt = True
#Const TxtFile_ReadOpen = True
#Const CreateFile = True
#Const CharSets_Enum = True
#Const TxtFile_WriteString = True
#Const TxtFile_WriteAppendEx = True
#Const Ellipsis_TextEnd = True
#Const HyperlinkList = True
#Const HookWindow = True
#Const UnhookWindow = True
#Const HyperlinkList_GetURLPointerFromItem = True
#Const OSVersionDependent = True
#Const LoadCursor = True
#Const TxtFile_ReadOpenEx = True
#Const HookedWindowProc = True
#Const WordWrapText = True
#Const DrawTextGetHeight = True
#Const DrawTextGetWidth = True
#Const GetTextExtentExPoint_FitInWidth = True

#Const asm_StrStrW_CrLf = True

Public Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
  End Type
Public Type FINDREPLACE
  lStructSize As Long
  hWndOwner As Long
  hInstance As Long
  Flags As Long
  lpstrFindWhat As Long
  lpstrReplaceWith As Long
  wFindWhatLen As Integer
  wReplaceWithLen As Integer
  lCustData As Long
  lpfnHook As Long
  lpTemplateName As Long
  End Type
Public Type POINTAPI
  x As Long
  y As Long
  End Type
Public Type STARTUPINFO
  cb As Long
  lpReservedL As Long
  lpDesktopL As Long
  lpTitleL As Long
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
  End Type
Public Type SYSTEMTIME
  wYear As Integer
  wMonth As Integer
  wDayOfWeek As Integer
  wDay As Integer
  wHour As Integer
  wMinute As Integer
  wSecond As Integer
  wMilliseconds As Integer
  End Type
Private Type OFNOTIFY
  HwndFrom As Long
  idfrom As Long
  code As Long
  lpOFN As Long
  pszfile As Long
  End Type
Private Type BrowseInfo
  hWndOwner As Long
  pIDLRoot As Long
  pszDisplayName As Long
  lpszTitle As Long
  ulFlags As Long
  lpfnCallback As Long
  lParam As Long
  iImage As Long
  End Type
Public Type LOGFONT
  lfHeight As Long
  lfWidth As Long
  lfEscapement As Long
  lfOrientation As Long
  lfWeight As Long
  lfItalic As Byte
  lfUnderline As Byte
  lfStrikeOut As Byte
  lfCharSet As Byte
  lfOutPrecision As Byte
  lfClipPrecision As Byte
  lfQuality As Byte
  lfPitchAndFamily As Byte
  lfFaceName(66) As Byte
  FontName As String
  End Type
Private Type FILETIME
  dwLowDateTime As Long
  dwHighDateTime As Long
  End Type
Public Type WIN32_FIND_DATA
  dwFileAttributes As Long
  ftCreationTime As FILETIME
  ftLastAccessTime As FILETIME
  ftLastWriteTime As FILETIME
  nFileSizeHigh As Long
  nFileSizeLow As Long
  dwReserved0 As Long
  dwReserved1 As Long
  Reserved_cFileName(521&) As Byte
  Reserved_cAlternate(29) As Byte
  Filename As String
  End Type
Private Type PROPSHEETHEADER
  dwSize As Long
  dwFlags As Long
  hWndParent As Long
  hInstance As Long
  hIcon As Long
  pszCaption As Long
  nPages As Long
  nStartPage As Long
  phpage As Long
  pnfCallback As Long
  End Type
Private Type PROPSHEETPAGE
  Size As Long
  Flags As Long
  hInstance As Long
  pResource As Long
  hIcon As Long
  pszTitle As Long
  pfnDlgProc As Long
  lParam As Long
  pfnCallback As Long
  pcRefParent As Long
  End Type
Public Type WNDCLASSEX
  cbSize As Long
  Style As Long
  lpfnWndProc As Long
  cbClsExtra As Long
  cbWndExtra As Long
  hInstance As Long
  hIcon As Long
  hCursor As Long
  hbrBackground As Long
  Reserved_lpszMenuName As Long
  Reserved_lpszClassName As Long
  hIconSm As Long
  ClassName As String
  End Type
Public Type NOTIFYICONDATA
  Reserved_cbsize As Long
  hWnd As Long
  uId As Long
  uFlags As Long
  uCallBackMessage As Long
  hIcon As Long
  Reserved_szTip(129&) As Byte
  ToolTip As String
  End Type
Public Type SHFILEOPSTRUCT
  hWnd As Long
  wFunc As Long
  Reserved_pFrom As Long
  Reserved_pTo As Long
  fFlags As Integer
  fAnyOperationsAborted As Long
  hNameMappings As Long
  Reserved_lpszProgressTitle As Long
  From As String
  End Type
Private Type MONITORINFO
  cbSize As Long
  rcMonitor As RECT
  rcWork As RECT
  dwFlags As Long
  End Type
Private Type ICONINFO
  fIcon As Long
  xHotspot As Long
  yHotspot As Long
  hbmMask As Long
  hbmColor As Long
  End Type
Private Type DEV_BROADCAST_HANDLE
  dbcc_size As Long
  dbcc_devicetype As Long
  dbcc_reserved As Long
  dbch_handle As Long
  dbch_hdevnotify As Long
  dbch_eventguid(15) As Byte
  dbch_nameoffset As Long
  dbch_data As Long
  End Type
Private Type LARGE_INTEGER
  lowpart As Long
  highpart As Long
  End Type
Private Type Single_TOKEN_PRIVILEGE
  PrivilegeCount As Long
  pLuid As LARGE_INTEGER
  Attributes As Long
  End Type
Private Type DELETEITEMSTRUCT
  CtlType As Long
  CtlID As Long
  ItemID As Long
  hwndItem As Long
  itemData As Long
  End Type
Private Type MEASUREITEMSTRUCT
  CtlType As Long
  CtlID As Long
  ItemID As Long
  itemWidth As Long
  itemHeight As Long
  itemData As Long
  End Type
Private Type DRAWITEMSTRUCT
  CtlType As Long
  CtlID As Long
  ItemID As Long
  itemAction As Long
  itemState As Long
  hwndItem As Long
  hdc As Long
  rcItem As RECT
  itemData As Long
  End Type

Public Declare Sub GetSystemTime Lib "kernel32.dll" (lpSystemTime As SYSTEMTIME)
Public Declare Function DrawTextW Lib "User32.dll" (ByVal hdc As Long, ByVal lpStr As Long, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Public Declare Function SetFocusAPI Lib "User32.dll" Alias "SetFocus" (ByVal hWnd As Long) As Long
Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32.dll" () As Long
Public Declare Function GetDC Lib "User32.dll" (ByVal hWnd As Long) As Long
Public Declare Function ReleaseDC Lib "User32.dll" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Public Declare Function ClientToScreen Lib "User32.dll" (ByVal hWnd As Long, ByRef lpPoint As Any) As Long
Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Public Declare Function GetSystemMetrics Lib "User32.dll" (ByVal nIndex As Long) As Long
Public Declare Function GetForegroundWindow Lib "User32.dll" () As Long
Public Declare Function SetForegroundWindow Lib "User32.dll" (ByVal hWnd As Long) As Long
Public Declare Function DestroyWindow Lib "User32.dll" (ByVal hWnd As Long) As Long
Public Declare Function EndDialog Lib "User32.dll" (ByVal hDlg As Long, ByVal nResult As Long) As Long
Public Declare Function GetTextExtentPoint32Wide Lib "gdi32.dll" Alias "GetTextExtentPoint32W" (ByVal hdc As Long, ByVal lpsz As Long, ByVal cbString As Long, ByRef lpSize As Any) As Long
Public Declare Function SetMenuDefaultItem Lib "User32.dll" (ByVal hMenu As Long, ByVal uItem As Long, ByVal fByPos As Long) As Long
Public Declare Function GetDlgItem Lib "User32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Public Declare Function LocalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal wBytes As Long) As Long
Public Declare Function LocalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
Public Declare Function CheckMenuItem Lib "User32.dll" (ByVal hMenu As Long, ByVal wIDCheckItem As Long, ByVal wCheck As Long) As Long
Public Declare Function DeleteMenu Lib "User32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function EnableMenuItem Lib "User32.dll" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Public Declare Function GetMenuItemCount Lib "User32.dll" (ByVal hMenu As Long) As Long
Public Declare Function GetMenuState Lib "User32.dll" (ByVal hMenu As Long, ByVal wID As Long, ByVal wFlags As Long) As Long
Public Declare Sub GetStartupInfoA Lib "kernel32.dll" (lpStartupInfo As STARTUPINFO)
Public Declare Function GetDriveTypeA Lib "kernel32.dll" (ByVal nDrive As String) As Long
Public Declare Function DrawMenuBar Lib "User32.dll" (ByVal hWnd As Long) As Long
Public Declare Function MessageBoxW Lib "User32.dll" (ByVal hWnd As Long, ByVal lpText As Long, ByVal lpCaption As Long, ByVal wType As Long) As Long
Public Declare Function SystemParametersInfoA Lib "User32.dll" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Declare Function EnableWindow Lib "User32.dll" (ByVal hWnd As Long, ByVal fEnable As Long) As Long
Public Declare Sub RtlMoveMemory Lib "kernel32.dll" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Public Declare Function GetCursorPos Lib "User32.dll" (lpPoint As Any) As Long
Public Declare Function GetDesktopWindow Lib "User32.dll" () As Long
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Public Declare Function GetWindowRect Lib "User32.dll" (ByVal hWnd As Long, lpRect As RECT) As Long
Public Declare Function DefWindowProcA Lib "User32.dll" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function DefWindowProcW Lib "User32.dll" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function CallWindowProcA Lib "User32.dll" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function CallWindowProcW Lib "User32.dll" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SystemParametersInfoW Lib "User32.dll" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Declare Function GetLogicalDrives Lib "kernel32.dll" () As Long
Public Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Public Declare Function SendMessageA Lib "User32.dll" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SendMessageW Lib "User32.dll" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetCommandLineW Lib "kernel32.dll" () As Long
Public Declare Function GetCommandLineA Lib "kernel32.dll" () As Long
Private Declare Function GetOpenFileNameA Lib "comdlg32.dll" (pOpenfilename As OPENFILENAME_Real) As Long
Private Declare Function GetOpenFileNameW Lib "comdlg32.dll" (pOpenfilename As OPENFILENAME_Real) As Long
Private Declare Function GetSaveFileNameA Lib "comdlg32.dll" (pOpenfilename As OPENFILENAME_Real) As Long
Private Declare Function GetSaveFileNameW Lib "comdlg32.dll" (pOpenfilename As OPENFILENAME_Real) As Long
Private Declare Function GetParent Lib "User32.dll" (ByVal hWnd As Long) As Long
Private Declare Function SHBrowseForFolderA Lib "shell32.dll" (lpBI As BrowseInfo) As Long
Private Declare Function SHBrowseForFolderW Lib "shell32.dll" (lpBI As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDListA Lib "shell32.dll" (ByVal pidList As Long, ByVal lpBuffer As Long) As Long
Private Declare Function SHGetPathFromIDListW Lib "shell32.dll" (ByVal pidList As Long, ByVal lpBuffer As Long) As Long
Private Declare Sub CoTaskMemFree Lib "Ole32.dll" (ByVal pv As Long)
Private Declare Function GetWindow Lib "User32.dll" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function ShowWindow Lib "User32.dll" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function CreateDialogIndirectParamA Lib "User32.dll" (ByVal hInstance As Long, ByVal lpTemplate As String, ByVal hWndParent As Long, ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Long
Private Declare Function CreateDialogIndirectParamW Lib "User32.dll" (ByVal hInstance As Long, ByVal lpTemplate As String, ByVal hWndParent As Long, ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Long
Private Declare Function CreateDirectoryA Lib "kernel32.dll" (ByVal lpPathName As String, ByVal lpSecurityAttributes As Long) As Long
Private Declare Function CreateDirectoryW Lib "kernel32.dll" (ByVal lpPathName As Long, ByVal lpSecurityAttributes As Long) As Long
Private Declare Function CreateFontIndirectA Lib "gdi32.dll" (ByVal lpLogFont As Long) As Long
Private Declare Function CreateFontIndirectW Lib "gdi32.dll" (ByVal lpLogFont As Long) As Long
Private Declare Function DragQueryFileA Lib "shell32.dll" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As Long, ByVal ch As Long) As Long
Private Declare Function DragQueryFileW Lib "shell32.dll" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As Long, ByVal ch As Long) As Long
Public Declare Sub DragFinish Lib "shell32.dll" (ByVal hDrop As Long)
Private Declare Function DrawTextA Lib "User32.dll" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function FindFirstChangeNotificationA Lib "kernel32.dll" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Private Declare Function FindFirstChangeNotificationW Lib "kernel32.dll" (ByVal lpPathName As Long, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function FindNextChangeNotification Lib "kernel32.dll" (ByVal hChangeHandle As Long) As Long
Public Declare Function FindCloseChangeNotification Lib "kernel32.dll" (ByVal hChangeHandle As Long) As Long
Private Declare Function FindFirstFileA Lib "kernel32.dll" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindFirstFileW Lib "kernel32.dll" (ByVal lpFileName As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFileA Lib "kernel32.dll" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFileW Lib "kernel32.dll" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long
Private Declare Function FindWindowA Lib "User32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowW Lib "User32.dll" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Public Declare Function SetMenu Lib "User32.dll" (ByVal hWnd As Long, ByVal hMenu As Long) As Long
Private Declare Function GetMenuItemRect Lib "User32.dll" (ByVal hWnd As Long, ByVal hMenu As Long, ByVal uItem As Long, lprcItem As RECT) As Long
Private Declare Function TrackPopupMenuEx Lib "User32.dll" (ByVal hMenu As Long, ByVal un As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal hWnd As Long, ByVal lpTPMParams As Long) As Long
Private Declare Function GetDlgItemTextA Lib "User32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As Long, ByVal nMaxCount As Long) As Long
Private Declare Function GetDlgItemTextW Lib "User32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As Long, ByVal nMaxCount As Long) As Long
Private Declare Function GetFileVersionInfoA Lib "Version.dll" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Function GetFileVersionInfoW Lib "Version.dll" (ByVal lptstrFilename As Long, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Function GetFileVersionInfoSizeA Lib "Version.dll" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfoSizeW Lib "Version.dll" (ByVal lptstrFilename As Long, lpdwHandle As Long) As Long
Private Declare Function VerQueryValueA Lib "Version.dll" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Long, puLen As Long) As Long
Private Declare Function VerQueryValueW Lib "Version.dll" (pBlock As Any, ByVal lpSubBlock As Long, lplpBuffer As Long, puLen As Long) As Long
Private Declare Function GetFileAttributesA Lib "kernel32.dll" (ByVal lpFileName As String) As Long
Private Declare Function GetFileAttributesW Lib "kernel32.dll" (ByVal lpFileName As Long) As Long
Private Declare Function GetFullPathNameA Lib "kernel32.dll" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As Long, ByVal lpFilePart As Long) As Long
Private Declare Function GetFullPathNameW Lib "kernel32.dll" (ByVal lpFileName As Long, ByVal nBufferLength As Long, ByVal lpBuffer As Long, ByVal lpFilePart As Long) As Long
Private Declare Function GetKeyNameTextA Lib "User32.dll" (ByVal lParam As Long, ByVal lpBuffer As Long, ByVal nSize As Long) As Long
Private Declare Function GetKeyNameTextW Lib "User32.dll" (ByVal lParam As Long, ByVal lpBuffer As Long, ByVal nSize As Long) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal nFolder As Long, ppidl As Long) As Long
Private Declare Function SHGetSpecialFolderLocationFromSHFolder Lib "shfolder.dll" Alias "SHGetSpecialFolderLocation" (ByVal hWndOwner As Long, ByVal nFolder As Long, ppidl As Long) As Long
Private Declare Function GetWindowLongA Lib "User32.dll" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowLongW Lib "User32.dll" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowTextA Lib "User32.dll" (ByVal hWnd As Long, ByVal lpString As Long, ByVal cch As Long) As Long
Private Declare Function GetWindowTextW Lib "User32.dll" (ByVal hWnd As Long, ByVal lpString As Long, ByVal cch As Long) As Long
Private Declare Function LoadLibraryA Lib "kernel32.dll" (ByVal lpLibFileName As String) As Long
Private Declare Function LoadLibraryW Lib "kernel32.dll" (ByVal lpLibFileName As Long) As Long
Public Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Long
Private Declare Function FindResourceA Lib "kernel32.dll" (ByVal hInstance As Long, ByVal lpName As String, ByVal lpType As String) As Long
Private Declare Function LoadResource Lib "kernel32.dll" (ByVal hInstance As Long, ByVal hResInfo As Long) As Long
Private Declare Function SizeofResource Lib "kernel32.dll" (ByVal hInstance As Long, ByVal hResInfo As Long) As Long
Private Declare Function LockResource Lib "kernel32.dll" (ByVal hResData As Long) As Long
Public Declare Function CheckDlgButton Lib "User32.dll" (ByVal hDlg As Long, ByVal nIDButton As Long, ByVal wCheck As Long) As Long
Public Declare Function IsDlgButtonChecked Lib "User32.dll" (ByVal hDlg As Long, ByVal nIDButton As Long) As Long
Private Declare Function CreatePropertySheetPageA Lib "comctl32.dll" (lppsp As PROPSHEETPAGE) As Long
Private Declare Function CreatePropertySheetPageW Lib "comctl32.dll" (lppsp As PROPSHEETPAGE) As Long
Private Declare Function PropertySheetA Lib "comctl32.dll" (lppsph As PROPSHEETHEADER) As Long
Private Declare Function PropertySheetW Lib "comctl32.dll" (lppsph As PROPSHEETHEADER) As Long
Private Declare Function LoadMenuA Lib "User32.dll" (ByVal hInstance As Long, ByVal lpString As String) As Long
Private Declare Function LoadMenuW Lib "User32.dll" (ByVal hInstance As Long, ByVal lpString As Long) As Long
Public Declare Function DestroyMenu Lib "User32.dll" (ByVal hMenu As Long) As Long
Private Declare Function InsertMenuA Lib "User32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, lpNewItem As Any) As Long
Private Declare Function InsertMenuW Lib "User32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Long) As Long
Private Declare Function GetMenuStringA Lib "User32.dll" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As Long, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
Private Declare Function GetMenuStringW Lib "User32.dll" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As Long, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
Private Declare Function CreatePopupMenu Lib "User32.dll" () As Long
Private Declare Function ModifyMenuA Lib "User32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As String) As Long
Private Declare Function ModifyMenuW Lib "User32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Long) As Long
Private Declare Function LoadStringA Lib "User32.dll" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As Long, ByVal nBufferMax As Long) As Long
Private Declare Function LoadStringW Lib "User32.dll" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As Long, ByVal nBufferMax As Long) As Long
Private Declare Function MapVirtualKeyA Lib "User32.dll" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function MapVirtualKeyW Lib "User32.dll" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function lstrcpynA Lib "kernel32.dll" (ByVal lpString1 As String, ByVal lpString2 As Long, ByVal iMaxLength As Long) As Long
Private Declare Function lstrcpynW Lib "kernel32.dll" (ByVal lpString1 As Long, ByVal lpString2 As Long, ByVal iMaxLength As Long) As Long
Private Declare Function lstrlenA Lib "kernel32.dll" (ByVal lpString As Long) As Long
Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long
Private Declare Function RegCreateKeyExA Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegCreateKeyExW Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpSubKey As Long, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long
Private Declare Function RegDeleteKeyA Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteKeyW Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpSubKey As Long) As Long
Private Declare Function RegDeleteValueA Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpValueName As String) As Long
Private Declare Function RegDeleteValueW Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpValueName As Long) As Long
Private Declare Function RegEnumKeyA Lib "advapi32.dll" (ByVal HKEY As Long, ByVal dwIndex As Long, ByVal lpName As Long, ByVal cbName As Long) As Long
Private Declare Function RegEnumKeyW Lib "advapi32.dll" (ByVal HKEY As Long, ByVal dwIndex As Long, ByVal lpName As Long, ByVal cbName As Long) As Long
Private Declare Function UnregisterClassA Lib "User32.dll" (ByVal lpClassName As String, ByVal hInstance As Long) As Long
Private Declare Function UnregisterClassW Lib "User32.dll" (ByVal lpClassName As Long, ByVal hInstance As Long) As Long
Private Declare Function RegisterClassExA Lib "User32.dll" (pcWndClassEx As WNDCLASSEX) As Integer
Private Declare Function RegisterClassExW Lib "User32.dll" (pcWndClassEx As WNDCLASSEX) As Integer
Private Declare Function RegOpenKeyExA Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegOpenKeyExW Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpSubKey As Long, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueExA Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByVal lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegQueryValueExW Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpValueName As Long, ByVal lpReserved As Long, ByVal lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueExA Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExW Lib "advapi32.dll" (ByVal HKEY As Long, ByVal lpValueName As Long, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function SetDlgItemTextA Lib "User32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As String) As Long
Private Declare Function SetDlgItemTextW Lib "User32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As Long) As Long
Private Declare Function ShellExecuteA Lib "shell32.dll" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function ShellExecuteW Lib "shell32.dll" (ByVal hWnd As Long, ByVal lpOperation As Long, ByVal lpFile As Long, ByVal lpParameters As Long, ByVal lpDirectory As Long, ByVal nShowCmd As Long) As Long
Private Declare Function Shell_NotifyIconA Lib "shell32.dll" (ByVal dwMessage As Long, lpData As Any) As Long
Private Declare Function Shell_NotifyIconW Lib "shell32.dll" (ByVal dwMessage As Long, lpData As Any) As Long
Private Declare Function SHFileOperationA Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Declare Function SHFileOperationW Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Declare Function ExitWindowsEx Lib "User32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function SetSystemPowerState Lib "kernel32.dll" (ByVal fSuspend As Long, ByVal fForce As Long) As Long
Private Declare Function SetWindowLongA Lib "User32.dll" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowLongW Lib "User32.dll" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowTextA Lib "User32.dll" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetWindowTextW Lib "User32.dll" (ByVal hWnd As Long, ByVal lpString As Long) As Long
Private Declare Function TextOutWide Lib "gdi32.dll" Alias "TextOutW" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, lpWideCharStr As Any, ByVal cchWideChar As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, lpDefaultChar As Any, lpUsedDefaultChar As Any) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, lpWideCharStr As Any, ByVal cchWideChar As Long) As Long
Private Declare Function SetEndOfFile Lib "kernel32.dll" (ByVal hFile As Long) As Long
Private Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function GetVersion Lib "kernel32.dll" () As Long
Private Declare Function GetShortPathNameW Lib "kernel32.dll" (ByVal lpszLongPath As Long, ByVal lpszShortPath As Long, ByVal cchBuffer As Long) As Long
Private Declare Function WinHelpA Lib "User32.dll" (ByVal hWnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, dwdata As Any) As Long
Private Declare Function WinHelpW Lib "User32.dll" (ByVal hWnd As Long, ByVal lpHelpFile As Long, ByVal wCommand As Long, dwdata As Any) As Long
Private Declare Function HtmlHelpA Lib "hhctrl.ocx" (ByVal hWndCaller As Long, ByVal pszfile As String, ByVal ucommand As Long, dwdata As Any) As Long
Private Declare Function HtmlHelpCloseA Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hWndCaller As Long, ByVal pszfile As Long, ByVal ucommand As Long, dwdata As Any) As Long
Private Declare Function HtmlHelpW Lib "hhctrl.ocx" (ByVal hWndCaller As Long, ByVal pszfile As Long, ByVal ucommand As Long, dwdata As Any) As Long
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function GetTimeFormatA Lib "kernel32.dll" (ByVal Locale As Long, ByVal dwFlags As Long, lpTime As SYSTEMTIME, ByVal lpFormat As Long, ByVal lpTimeStr As Long, ByVal cchTime As Long) As Long
Private Declare Function GetTimeFormatW Lib "kernel32.dll" (ByVal Locale As Long, ByVal dwFlags As Long, lpTime As SYSTEMTIME, ByVal lpFormat As Long, ByVal lpTimeStr As Long, ByVal cchTime As Long) As Long
Public Declare Function DestroyIcon Lib "User32.dll" (ByVal hIcon As Long) As Long
Private Declare Function VirtualAlloc Lib "kernel32.dll" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualProtect Lib "kernel32.dll" (lpAddress As Any, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
Private Declare Function VirtualFree Lib "kernel32.dll" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function FormatMessageW Lib "kernel32.dll" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As Long, ByVal nSize As Long, ByVal Arguments As Long) As Long
Private Declare Function FormatMessageA Lib "kernel32.dll" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, lpBuffer As Any, ByVal nSize As Long, ByVal Arguments As Long) As Long
Private Declare Function GetClassNameA Lib "User32.dll" (ByVal hWnd As Long, ByVal lpClassName As Long, ByVal nMaxCount As Long) As Long
Private Declare Function GetClassNameW Lib "User32.dll" (ByVal hWnd As Long, ByVal lpClassName As Long, ByVal nMaxCount As Long) As Long
Private Declare Function CreateWaitableTimerA Lib "kernel32.dll" (ByVal lpSemaphoreAttributes As Long, ByVal bManualReset As Long, ByVal lpName As Long) As Long
Private Declare Function CreateWaitableTimerW Lib "kernel32.dll" (ByVal lpSemaphoreAttributes As Long, ByVal bManualReset As Long, ByVal lpName As Long) As Long
Private Declare Function SetWaitableTimer Lib "kernel32.dll" (ByVal hTimer As Long, lpDueTime As FILETIME, ByVal lPeriod As Long, ByVal pfnCompletionRoutine As Long, ByVal lpArgToCompletionRoutine As Long, ByVal fResume As Long) As Long
Private Declare Function MsgWaitForMultipleObjects Lib "User32.dll" (ByVal nCount As Long, pHandles As Long, ByVal fWaitAll As Long, ByVal dwMilliseconds As Long, ByVal dwWakeMask As Long) As Long
Private Declare Function CreateWindowExA Lib "User32.dll" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByVal lpParam As Long) As Long
Private Declare Function CreateWindowExW Lib "User32.dll" (ByVal dwExStyle As Long, ByVal lpClassName As Long, ByVal lpWindowName As Long, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByVal lpParam As Long) As Long
Private Declare Function GetMonitorInfoA Lib "User32.dll" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long
Private Declare Function MonitorFromPoint Lib "User32.dll" (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As Long
Private Declare Function PostMessageA Lib "User32.dll" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function PostMessageW Lib "User32.dll" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetIconInfo Lib "User32.dll" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long
Private Declare Function DialogBoxIndirectParamA Lib "User32.dll" (ByVal hInstance As Long, ByVal hDialogTemplate As String, ByVal hWndParent As Long, ByVal lpDialogFunc As Long, ByVal xParam As Long) As Long
Private Declare Function DialogBoxIndirectParamW Lib "User32.dll" (ByVal hInstance As Long, ByVal hDialogTemplate As String, ByVal hWndParent As Long, ByVal lpDialogFunc As Long, ByVal xParam As Long) As Long
Private Declare Function LoadImageA Lib "User32.dll" (ByVal hInst As Long, lpsz As Any, ByVal uType As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal fuLoad As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function RegisterDeviceNotificationA Lib "User32.dll" (ByVal hRecipient As Long, NotificationFilter As Any, ByVal Flags As Long) As Long
Public Declare Function UnregisterDeviceNotification Lib "User32.dll" (ByVal hRecipient As Long) As Long
Private Declare Function CreateFileA Lib "kernel32.dll" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValueA Lib "advapi32.dll" (lpSystemName As Any, ByVal lpName As String, lpLuid As LARGE_INTEGER) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As Any, ByVal BufferLength As Long, PreviousState As Any, ReturnLength As Long) As Long
Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CreateFileW Lib "kernel32.dll" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function DrawTextADirect Lib "User32.dll" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As Long, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetClientRect Lib "User32.dll" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function GetBkColor Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function GetTextColor Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function FillRect Lib "User32.dll" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function GetSysColor Lib "User32.dll" (ByVal nIndex As Long) As Long
Private Declare Function SetBkColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function SetTextColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function DrawIconEx Lib "User32.dll" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function GetDlgCtrlID Lib "User32.dll" (ByVal hWnd As Long) As Long
Private Declare Function DrawFocusRect Lib "User32.dll" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function LoadCursorA Lib "User32.dll" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Private Declare Function LoadCursorW Lib "User32.dll" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Private Declare Function GetFileSize Lib "kernel32.dll" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hFile As Long, ByVal lDistanceToMove As Long, ByVal lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function GetTextExtentExPointA Lib "gdi32.dll" (ByVal hdc As Long, ByVal lpszStr As String, ByVal cchString As Long, ByVal nMaxExtent As Long, lpnFit As Long, alpDx As Any, lpSize As Any) As Long
Private Declare Function GetTextExtentExPointW Lib "gdi32.dll" (ByVal hdc As Long, ByVal lpszStr As Long, ByVal cchString As Long, ByVal nMaxExtent As Long, lpnFit As Long, alpDx As Any, lpSize As Any) As Long


Public Const DoEventsEx_SleepPeriodical_Interval = 200&
#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
Private Type GetSaveFilename_CustomParams
  LenFilters As Long
  ErrExistsTitle As Long
  ErrExistsText As Long
  ErrROTitle As Long
  ErrROText As Long
  RealResult As Long
  End Type
Private Const GetSaveFilename_CustomParamsLen As Long = 24&
Private CommonDLG_OpenPath_CurDir As Long
Private Const LayerVersionID As Long = &H10001010
Private hModul As Long
Private ctSSLayer_CanUseItemInt As Long
Private ctSSLayer_LoadSongInt As Long
Private ctSSLayer_LoadSongPlayInt As Long
#If ctSSLayer_LoadSongAbort Then
  Private ctSSLayer_LoadSongAbortInt As Long
  #End If
#If ctSSLayer_LoadSongFinished Then
  Private ctSSLayer_LoadSongFinishedInt As Long
  #End If
Private ctSSLayer_UnloadSongInt As Long
#If ctSSLayer_GetInfoString Then
  Private ctSSLayer_GetInfoStringInt As Long
  #End If
#If ctSSLayer_GetPosition Then
  Private ctSSLayer_GetPositionInt As Long
  #End If
#If ctSSLayer_SeekSong Then
  Private ctSSLayer_SeekSongInt As Long
  #End If
#If ctSSLayer_SetPause Then
  Private ctSSLayer_SetPauseInt As Long
  #End If
#If ctSSLayer_SetVolume Then
  Private ctSSLayer_SetVolumeInt As Long
  #End If
#If ctSSLayer_GetSongLength Then
  Private ctSSLayer_SongLengthInt As Long
  #End If
Private ctSSLayer_GetDeviceNameInt As Long
Private ctSSLayer_GetDeviceSSLIDInt As Long
#If ctSSLayer_Spectrum Then
  Private ctSSLayer_GetSpectrumInt As Long
  #End If
#If ctSSLayer_MusicGetPattern Then
  Private ctSSLayer_MusicGetPatternInt As Long
  #End If
#If ctSSLayer_MusicGetPatterns Then
  Private ctSSLayer_MusicGetPatternsInt As Long
  #End If
#If ctSSLayer_MusicHasFinished Then
  Private ctSSLayer_MusicHasFinishedInt As Long
  #End If
#If ctSSLayer_MusicTime Then
  Private ctSSLayer_MusicTimeInt As Long
  #End If
Private ctSSLayer_ReadSongInfoInt As Long
Public Type ctSSLayerSongInfoStruct
  FormatOK As Long ' Boolean
  Format_Frequency As Long
  Format_BitRate As Long
  Format_Channels As Long
  Format_VBR As Long ' Boolean
  Format_QualityMulti As Single
  TagOK As Long 'Boolean
  Tag_Year As Long
  Tag_TrackID As Long
  Tag_Artist As String
  Tag_Title As String
  Tag_Album As String
  IR_Name As String
  IR_URL As String
  End Type
Private Const SleepValueHigh As Long = 100&
'see also consts in DoEventsEx
Public Enum GetFileVersionField_Enum
  GetFileVersionField_Comments
  GetFileVersionField_CompanyName
  GetFileVersionField_FileDesc
  GetFileVersionField_FileVersion
  GetFileVersionField_InternalName
  GetFileVersionField_LegalCopyright
  GetFileVersionField_LegalTrademarks
  GetFileVersionField_OriginalFilename
  GetFileVersionField_PrivateBuild
  GetFileVersionField_ProductName
  GetFileVersionField_ProductVersion
  GetFileVersionField_SpecialBuild
  End Enum
Dim GetTextOutWidth_PointApi As POINTAPI
Private Const LoadResEx_Dialog_Disabled = -1&
Private Type LoadResEx_Dialog_DialogInfo
  xEscBehaviour As Long
  xButtonCtlID As Long
  xCallBackProc As Long
  End Type
Private Const LoadResEx_Dialog_DialogInfoSize = 12&
#If InIDE And Not LoadResEx_SetLanguageFile Then
  Private Declare Function LoadMenuInIDEW Lib "user32" Alias "LoadMenuIndirectW" (lpMenuTemplate As Any) As Long
  Private Declare Function LoadMenuInIDEA Lib "user32" Alias "LoadMenuIndirectA" (lpMenuTemplate As Any) As Long
  #End If
Public LoadResEx_LanguageFile_hModule As Long
Public LoadResEx_ThemeFile_hModule As Long
Public Enum ShutDownWindowsEx_Mode
  SDWE_Shutdown = 1
  SDWE_Hibernate = 2
  SDWE_Standby = 3
  SDWE_MonitorsOff = 4
  End Enum
Private Type TxtFileWriteStruct
  hFile As Long
  ' same offset as in read counterpart!!!
  Encoding As Long
  End Type
Private Const TxtFileWriteStructLen As Long = 8&
Public IsUnicode As Boolean
Private Type HyperLinkList_InfoDialog_Data
  IconID As Long
  hIcon As Long
  CallBack As Long
  HListID As Long
  'FocusID As Long
  CallURL As Long
  End Type
Private Const HyperLinkList_InfoDialog_DataLen As Long = 20& ' 24&
Private CallFunction_tmpArray() As Byte
Private CallFunction_tmpParam() As Long
Private CallFunction_tmpPAPos As Long
Private Const OPENFILENAME_DataSize As Long = 32760&
Private Const OPENFILENAME_DataSizeW As Long = (OPENFILENAME_DataSize) * 2&
Public Type OPENFILENAME
  hWndOwner As Long
  Filter As String
  FilterIndex As Long
  Title As String
  InitialDirFile As String
  ' Save Mode Only:
#If GetSaveFileName Then
  DefExt As String
  ErrExistsTitle As String
  ErrExistsText As String
  ErrROTitle As String
  ErrROText As String
#End If
  End Type
Private Type OPENFILENAME_Real
  lStructSize As Long
  hWndOwner As Long
  hInstance As Long
  lpstrFilter As Long
  lpstrCustomFilter As Long
  nMaxCustFilter As Long
  nFilterIndex As Long
  lpstrFile As Long
  nMaxFile As Long
  lpstrFileTitle As Long
  nMaxFileTitle As Long
  lpstrInitialDir As Long
  lpstrTitle As Long
  Flags As Long
  nFileOffset As Integer
  nFileExtension As Integer
  lpstrDefExt As Long
  lCustData As Long
  lpfnHook As Long
  lpTemplateName As Long
#If GetSaveFileName Then
  Ext_SaveName As String
#End If
  End Type
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&
Private Const SleepValueLow As Long = 25&
Private DoEventsEx_Sleep_WaitableTimers As Boolean
'see also consts in DoEventsEx
Public Enum LoadResEx_IconOS
  LoadResEx_IconOS_Win95_16Color '16bit, 95NT+
  LoadResEx_IconOS_Win95 'truecolor, 95NT+
  LoadResEx_IconOS_WinNT
  LoadResEx_IconOS_Win98
  LoadResEx_IconOS_Win2000ME_16Color
  LoadResEx_IconOS_Win2000ME
  LoadResEx_IconOS_WinXP
  LoadResEx_IconOS_WinVista
  End Enum
Private LoadResex_Caps_TrayIcon As Long
Private LoadResex_Caps_WinDIcon As Long
Private LoadResEx_IsHighColor As Boolean
Private RemovableDevices_Handle(0& To 25&) As Long
Private Type TxtFileReadStruct
  hMem As Long
  ' Same position as in Write Struct!!!!
  Encoding As Long
  hMemPos As Long
  #If TxtFile_SetEncoding Or TxtFile_ReadLine Or TxtFile_ReadCompleteString Then
    hMemEnd As Long
    #End If
  End Type
#If TxtFile_SetEncoding Or TxtFile_ReadLine Or TxtFile_ReadCompleteString Then
  Private Const TxtFileReadStructLen As Long = 16&
  #Else
  Private Const TxtFileReadStructLen As Long = 12&
  #End If
Public Enum eCreateFileOpenMode
  CreateAlwaysNew = 2&
  OpenExisting = 3&
  CreateOrReuse = 4&
  End Enum
Public Enum eCreateFileAccessMode
  FILE_READ = &H80000000
  FILE_WRITE = &H40000000
  FILE_READWRITE = &HC0000000
  End Enum
Public Enum TxtFile_EncodingEnum
  CP_ACP = 0&
  CP_UTF8 = 65001
  CP_WINUNICODE = 1200&
  End Enum
Private Type HyperlinkListItemStruct
  xText As Long
  LenText As Long
  LnkRect As RECT
  LnkURL As Long
  LnkCaption As Long
  LnkCapLen As Long
  xHeight As Long
  #If HyperlinkList_UseIcons Then
    hIcon As Long
    IconIdent As Long
    IconSize As Long
    #End If
  Padding As RECT
  End Type
#If HyperlinkList_UseIcons Then
  Private Const HyperlinkListItemLen As Long = 17& * 4&
  #Else
  Private Const HyperlinkListItemLen As Long = 14& * 4&
  #End If
Private Const HyperlinkList_PaddingIcon As Long = 4&
#If SetIsMinWindowsXP Then
  Public IsMinWindowsXP As Boolean
  #End If
#If SetIsMinWindows2000W Then
  Public IsMinWindows2000W As Boolean
  #End If
#If SetIsMinWindows982000 Then
  Public IsMinWindows982000 As Boolean
  #End If
Private Const StrStrW_CrLf_Bin As String = "568B74241009F6741DFC66AD6609C074156683F80D75F366AD6683F80A75ED83EE0489F0EB0231C05EC21000"
Private StrStrW_CrLf_Mem As Long
Private StrStrW_CrLf_Exe As Long

Public Function CalaymMessageBox(ByVal hWndOwner As Long, ByVal Prompt As String, ByVal Title As String, ByVal Buttons As Long) As Long
  DialogTimer True
  CalaymMessageBox = MessageBoxW(hWndOwner, StrPtr(Prompt), StrPtr(Title), Buttons)
  DialogTimer False
  End Function

Public Function LoadResEx_Dialog_CheckLongManualHandle(ByVal DialogHWnd As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Dim xLong1 As Long
  'x = (x + 2) % 3 for direct
  xLong1 = (wParam And &HFFFF&)
  LoadResEx_Dialog_CheckLongManualHandle = -1&
  
  If Not lParam = 0& Then
    If (GetWindowLong(lParam, -16&) And &HF&) = &H5& Then
      wParam = (IsDlgButtonChecked(DialogHWnd, xLong1) + 2&) Mod 3&
      Call CheckDlgButton(DialogHWnd, xLong1, wParam)
      LoadResEx_Dialog_CheckLongManualHandle = (3& - wParam) Mod 3&
      Call SetDlgItemText(DialogHWnd, xLong1, LoadResEx_String(xLong1 + LoadResEx_Dialog_CheckLongManualHandle))
      End If
    End If
  End Function

Public Function LoadResEx_Dialog_CheckLong(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByRef Value As Long, Optional ByVal ReadFromDialog As Boolean = False) As Boolean ', Optional ByVal ResStringIDFirst As Long = -1&) As Boolean
  Dim xLong1 As Long
  'x=(3-x) % 3
  
  xLong1 = GetDlgItem(DialogHWnd, ControlID)
  If Not xLong1 = 0& Then
    xLong1 = (GetWindowLong(xLong1, -16&) And &HF&)
    If ReadFromDialog Then
      If Not GetDlgItem(DialogHWnd, ControlID) = 0& Then
        ControlID = IsDlgButtonChecked(DialogHWnd, ControlID)
        If xLong1 = &H5& Then ControlID = ((3& - ControlID) Mod 3&)
        If Not ControlID = Value Then
          Value = ControlID
          LoadResEx_Dialog_CheckLong = True
          End If
        End If
      Else
      'If ResStringIDFirst = -1& Then ResStringIDFirst = ControlID
      Call SetDlgItemText(DialogHWnd, ControlID, LoadResEx_String(ControlID + Value))
      If xLong1 = &H5& Then xLong1 = ((3& - Value) Mod 3&)
      Call CheckDlgButton(DialogHWnd, ControlID, xLong1)
      'Call SetDlgItemTextA(DialogHWnd, ControlID, LoadResEx_String(ResStringIDFirst + Value))
      End If
    End If
  End Function

Public Function ApplicationStart(Optional ByVal MaxIconSupport As Long = 0&) As Boolean
  #If ListView Then
    Dim xType1 As InitCommonControlsExType
    #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 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

Public Sub ArraySort_String_IC(ByRef xArray() As String, ByVal ElementsToSort As Long)
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xChar1 As String

  'Shell Sort algorithm!

  ElementsToSort = ElementsToSort - 1&
  Do
    xLong1 = 3& * xLong1 + 1&
    Loop Until xLong1 > ElementsToSort
  Do
    xLong1 = xLong1 \ 3&
    For xLong2 = xLong1 To ElementsToSort
      xChar1 = xArray(xLong2)
      For xLong3 = xLong2 - xLong1 To 0& Step -xLong1
        If StrComp(xArray(xLong3), xChar1, vbTextCompare) < 1 Then Exit For
        xArray(xLong3 + xLong1) = xArray(xLong3)
        Next
      xArray(xLong3 + xLong1) = xChar1
      Next
    Loop While xLong1
  End Sub

Public Sub ArraySort_String_StartPos_IC(ByRef xArray() As String, ByVal ElementsToSort As Long, Optional ByVal StartPos As Long = 0&)
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xChar1 As String

  'Shell Sort algorithm!

  ElementsToSort = ElementsToSort - 1&
  Do
    xLong1 = 3& * xLong1 + 1&
    Loop Until xLong1 > ElementsToSort
  Do
    xLong1 = xLong1 \ 3&
    For xLong2 = xLong1 + StartPos To ElementsToSort + StartPos
      xChar1 = xArray(xLong2)
      For xLong3 = xLong2 - xLong1 To StartPos Step -xLong1
        If StrComp(xArray(xLong3), xChar1, vbTextCompare) < 1 Then Exit For
        xArray(xLong3 + xLong1) = xArray(xLong3)
        Next
      xArray(xLong3 + xLong1) = xChar1
      Next
    Loop While xLong1
  End Sub

Public Function CallFunction_Fast(ByVal FunctionAddress As Long, ParamArray FunctionParams()) As Long
  Dim xLong1 As Long
    
  ReDim CallFunction_tmpParam(UBound(FunctionParams()) + 1&)
  For xLong1 = 0& To UBound(FunctionParams())
    CallFunction_tmpParam(xLong1) = FunctionParams(xLong1)
    Next
  
  CallFunction_Fast = CallFunction_Real(FunctionAddress)
  End Function

Public Function CallFunction_Indirect(ByVal DllHandle As Long, ByVal FunctionName As Variant, ParamArray FunctionParams()) As Long
  Dim xLong1 As Long
  Dim xChar1 As String

  ReDim CallFunction_tmpParam(UBound(FunctionParams()) + 1&)
  For xLong1 = 0& To UBound(FunctionParams())
    CallFunction_tmpParam(xLong1) = FunctionParams(xLong1)
    Next
    
  If VarType(FunctionName) = vbString Then
    xChar1 = FunctionName
    Else
    xChar1 = FunctionName = "#" + CStr(Val(FunctionName))
    End If
  xLong1 = GetProcAddress(DllHandle, xChar1)
  If Not xLong1 = 0& Then
    CallFunction_Indirect = CallFunction_Real(xLong1)
#If InIDE Then
    Else
    Debug.Print "Cannot CallFunction_Indirect, function '" + xChar1 + "' not found"
#End If
    End If
  End Function

Public Function GetOpenFileName(ByRef xType1 As OPENFILENAME) As String
  Dim xLong1 As Long
  Dim xType2 As OPENFILENAME_Real

  Call OPENFILENAME_Patch(xType1, xType2)
  xType2.Flags = &H81004
  If IsUnicode Then
    xLong1 = GetOpenFileNameW(xType2)
    Else
    xLong1 = GetOpenFileNameA(xType2)
    End If
  If Not xLong1 = 0& Then GetOpenFileName = PeekS(xType2.lpstrFile)
  Call OPENFILENAME_Free(xType2)
  End Function

Public Function GetOpenFileName_MultiDataString(ByRef xType1 As OPENFILENAME) As String
  Dim xType2 As OPENFILENAME_Real
  Dim xLong1 As Long

  Call OPENFILENAME_Patch(xType1, xType2)
  xType2.Flags = &H81204
  If IsUnicode Then
    xLong1 = GetOpenFileNameW(xType2)
    Else
    xLong1 = GetOpenFileNameA(xType2)
    End If
  If Not xLong1 = 0& Then
    GetOpenFileName_MultiDataString = String(OPENFILENAME_DataSize, vbNullChar)
    If IsUnicode Then
      Call RtlMoveMemory(ByVal StrPtr(GetOpenFileName_MultiDataString), ByVal xType2.lpstrFile, OPENFILENAME_DataSizeW)
      Else
      Call RtlMoveMemory(ByVal GetOpenFileName_MultiDataString, ByVal xType2.lpstrFile, OPENFILENAME_DataSize)
      End If
    xLong1 = InStr(GetOpenFileName_MultiDataString, vbNullChar & vbNullChar)
    If xLong1 = 0& Then
      GetOpenFileName_MultiDataString = ""
      Else
      GetOpenFileName_MultiDataString = Left(GetOpenFileName_MultiDataString, xLong1 + 1&)
      End If
   End If
  Call OPENFILENAME_Free(xType2)
  End Function

Public Function GetSaveFileName(ByRef xType1 As OPENFILENAME) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType2 As OPENFILENAME_Real
  Dim xType3 As GetSaveFilename_CustomParams
  
  xLong1 = LocalAlloc(0&, GetSaveFilename_CustomParamsLen)
  If Not xLong1 = 0& Then
'    Stop
    With xType3
      If Not Len(xType1.ErrExistsTitle) = 0& Then
        .ErrExistsTitle = LocalAllocFromString_Wide(xType1.ErrExistsTitle)
        End If
      If Len(xType1.ErrExistsText) = 0& Then
        .ErrExistsText = LocalAllocFromString_Wide(FormatMessage(&H1200&, 0&, 80&))
        Else
        .ErrExistsText = LocalAllocFromString_Wide(xType1.ErrExistsText)
        End If
      If Not Len(xType1.ErrROTitle) = 0& Then
        .ErrROTitle = LocalAllocFromString_Wide(xType1.ErrROTitle)
        End If
      If Len(xType1.ErrROText) = 0& Then
        .ErrROText = LocalAllocFromString_Wide(FormatMessage(&H1200&, 0&, 82&))
        Else
        .ErrROText = LocalAllocFromString_Wide(xType1.ErrROText)
        End If
      End With
    
    Call OPENFILENAME_Patch(xType1, xType2)
    xType3.LenFilters = xType2.lCustData
    xType2.lCustData = xLong1
    Call RtlMoveMemory(ByVal xLong1, xType3, GetSaveFilename_CustomParamsLen)
    With xType2
      If Not Len(xType2.Ext_SaveName) = 0& Then
        xLong1 = InStrRev(xType2.Ext_SaveName, ".")
        If Not xLong1 = 0& Then
          xLong2 = GetSaveFileName_FindFilterIndex(xType2.lpstrFilter, xType3.LenFilters, Mid(xType2.Ext_SaveName, xLong1 + 1&))
          If Not xLong2 = 0& Then
            '.lpstrDefExt = LocalAllocFromString(Mid(xChar1, xLong1 + 1&))
            .nFilterIndex = xLong2
            xType2.Ext_SaveName = Left(xType2.Ext_SaveName, xLong1 - 1&)
            End If
          End If
        If Not .lpstrFile = 0& Then
          Call PokeS(.lpstrFile, xType2.Ext_SaveName, 256&)
          End If
        End If
  
      'FileMode = FileMode Or &H80020
      'If (FileMode And &H2&) = &H2& Then FileMode = FileMode - &H2&
      .lpfnHook = GetAddressOf(AddressOf GetSaveFileName_Hook)
      .Flags = &H80024
  
      End With
    If IsUnicode Then
      xLong1 = GetSaveFileNameW(xType2)
      Else
      xLong1 = GetSaveFileNameA(xType2)
      End If
    Call RtlMoveMemory(xType3, ByVal xType2.lCustData, GetSaveFilename_CustomParamsLen)
    If Not xLong1 = 0& Then
      If Not xType3.RealResult = 0& Then
        GetSaveFileName = PeekS(xType3.RealResult)
        End If
      End If
    xType1.FilterIndex = xType2.nFilterIndex
    Call OPENFILENAME_Free(xType2)
    With xType3
      If Not .ErrExistsTitle = 0& Then Call LocalFree(.ErrExistsTitle)
      If Not .ErrExistsText = 0& Then Call LocalFree(.ErrExistsText)
      If Not .ErrROTitle = 0& Then Call LocalFree(.ErrROTitle)
      If Not .ErrROText = 0& Then Call LocalFree(.ErrROText)
      If Not .RealResult = 0& Then Call LocalFree(.RealResult)
      End With
    Call LocalFree(xType2.lCustData)
    End If
  End Function

Private Function GetSaveFileName_GetFilterString(ByVal ptrFilter As Long, ByVal LenFilters As Long, ByRef xChar1 As String) As Boolean
  If Not (ptrFilter = 0& Or LenFilters = 0&) Then
    xChar1 = String(LenFilters, vbNullChar)
    If IsUnicode Then
      Call RtlMoveMemory(ByVal StrPtr(xChar1), ByVal ptrFilter, LenFilters * 2&)
      Else
      Call RtlMoveMemory(ByVal xChar1, ByVal ptrFilter, LenFilters)
      End If
    GetSaveFileName_GetFilterString = True
    End If
  End Function

Private Function GetSaveFileName_FindFilterIndex(ByVal ptrFilter As Long, ByVal LenFilters As Long, ByVal Extension As String) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  Dim xChar2 As String
  
  If GetSaveFileName_GetFilterString(ptrFilter, LenFilters, xChar1) Then
    Do
      xLong1 = InStr(xLong2 + 1&, xChar1, vbNullChar)
      If xLong1 = 0& Then Exit Do
      xLong2 = InStr(xLong1 + 1&, xChar1, vbNullChar)
      If xLong2 = 0& Then Exit Do
      GetSaveFileName_FindFilterIndex = GetSaveFileName_FindFilterIndex + 1&
      xChar2 = Mid(xChar1, xLong1 + 1&, xLong2 - xLong1 - 1&) + ";"
      If Not InStr(xChar2, "*." + Extension + ";") = 0& Then
        Exit Function
        End If
      Loop
    End If
  GetSaveFileName_FindFilterIndex = 0&
  End Function

Private Function GetSaveFileName_ExtensionByIndex(ByVal ptrFilter As Long, ByVal LenFilters As Long, ByVal Index As Long) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  
  If Index > 0& Then
    If GetSaveFileName_GetFilterString(ptrFilter, LenFilters, xChar1) Then
      Do
        xLong1 = InStr(xLong2 + 1&, xChar1, vbNullChar)
        If xLong1 = 0& Then Exit Do
        xLong2 = InStr(xLong1 + 1&, xChar1, vbNullChar)
        If xLong2 = 0& Then Exit Do
        Index = Index - 1&
        If Index = 0& Then
          GetSaveFileName_ExtensionByIndex = Mid(xChar1, xLong1 + 1&, xLong2 - xLong1 - 1&) + ";"
          GetSaveFileName_ExtensionByIndex = Left(GetSaveFileName_ExtensionByIndex, InStr(GetSaveFileName_ExtensionByIndex, ";") - 1&)
          If Left(GetSaveFileName_ExtensionByIndex, 2&) = "*." Then
            GetSaveFileName_ExtensionByIndex = Mid(GetSaveFileName_ExtensionByIndex, 3&)
            Exit Function
            End If
          Exit Do
          End If
        Loop
      GetSaveFileName_ExtensionByIndex = ""
      End If
    End If
  End Function

Private Function GetSaveFileName_HookHandle(ByVal hDlgChild As Long, ByVal ptrNMHDR As Long) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType1 As OFNOTIFY
  Dim xType2 As OPENFILENAME_Real
  Dim xType3 As GetSaveFilename_CustomParams
  Dim xChar1 As String
  Dim xChar2 As String
  
'Public Const FILE_ATTRIBUTE_READONLY = &H1
'Public Const FILE_ATTRIBUTE_HIDDEN = &H2
'Public Const FILE_ATTRIBUTE_SYSTEM = &H4
'Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
  
  ' 4*4 = filters
  ' 7*4 = index
  Call RtlMoveMemory(xType1, ByVal ptrNMHDR, 16&)
  If xType1.code = -607& Then
    If Not xType1.lpOFN = 0& Then
      Call RtlMoveMemory(xType2, ByVal xType1.lpOFN, 17& * 4&)
      If Not (xType2.lpstrFilter = 0& Or xType2.lCustData = 0&) Then
        Call RtlMoveMemory(xType3, ByVal xType2.lCustData, GetSaveFilename_CustomParamsLen)
        hDlgChild = GetParent(hDlgChild)
        If Not hDlgChild = 0& Then
          xChar1 = GetDlgItemText(hDlgChild, &H480&)
          If Not Len(xChar1) = 0& Then
            xLong1 = InStrRev(xChar1, ".")
            If Not xLong1 = 0& Then
              xLong2 = GetSaveFileName_FindFilterIndex(xType2.lpstrFilter, xType3.LenFilters, Mid(xChar1, xLong1 + 1&))
              If Not (xLong2 = 0& Or xLong2 = xType2.nFilterIndex) Then
                xChar1 = Left(xChar1, xLong1 - 1&)
                Call SendMessage_String(hDlgChild, 1128&, &H480&, ByVal xChar1)
                End If
              End If
            End If
          End If
        End If
      End If
    ElseIf xType1.code = -606& Then
    If Not xType1.lpOFN = 0& Then
      Call RtlMoveMemory(xType2, ByVal xType1.lpOFN, 17& * 4&)
      If Not (xType2.lpstrFile = 0& Or xType2.lCustData = 0&) Then
        Call RtlMoveMemory(xType3, ByVal xType2.lCustData, GetSaveFilename_CustomParamsLen)
        xChar1 = PeekS(xType2.lpstrFile)
        If Not Len(xChar1) = 0& Then
          '' check attributes
          xLong1 = InStrRev(xChar1, ".")
          If Not xLong1 = 0& Then
            If Not GetSaveFileName_FindFilterIndex(xType2.lpstrFilter, xType3.LenFilters, Mid(xChar1, xLong1 + 1&)) = 0& Then
              GoTo FilenameComplete
              End If
            End If
          xChar1 = xChar1 + "." + GetSaveFileName_ExtensionByIndex(xType2.lpstrFilter, xType3.LenFilters, xType2.nFilterIndex)
FilenameComplete:
          xLong1 = GetFileAttributes(xChar1)
          If xLong1 = -1& Then GoTo Ok
          If (xLong1 And &H17&) = 0& Then
            xChar2 = Replace(PeekS_Wide(xType3.ErrExistsText), "$F", xChar1)
            If MessageBoxW(GetParent(hDlgChild), StrPtr(xChar2), xType3.ErrExistsTitle, vbOKCancel Or vbExclamation) = vbOK Then
Ok:
              'Call PokeS(xType2.lpstrFile, xChar1, 256&)
              If Not xType3.RealResult = 0& Then Call LocalFree(xType3.RealResult)
              xType3.RealResult = LocalAllocFromString(xChar1)
              Call RtlMoveMemory(ByVal xType2.lCustData, xType3, GetSaveFilename_CustomParamsLen)
              Exit Function
              End If
            Else
            xChar2 = Replace(PeekS_Wide(xType3.ErrROText), "$F", xChar1)
            Call MessageBoxW(GetParent(hDlgChild), StrPtr(xChar2), xType3.ErrROTitle, vbExclamation)
            End If
          End If
        End If
      'Debug.Print "Result:"; xChar1
      End If
    
    Call SetWindowLong(hDlgChild, 0&, 1&)
    GetSaveFileName_HookHandle = 1&
    End If
  End Function

Private Function GetSaveFileName_Hook(ByVal hDlgChild As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  'Debug.Print Msg
  Select Case Msg
    Case &H4E& ' WM_Notify
      GetSaveFileName_Hook = GetSaveFileName_HookHandle(hDlgChild, lParam)
    End Select
  End Function

Public Function CommonDLG_OpenPath(ByVal hWnd As Long, ByVal Caption As String, Optional ByVal InitDir As String) As String
  Dim xLong1 As Long
  Dim xType1 As BrowseInfo
    
  xType1.hWndOwner = hWnd
  xType1.lpszTitle = LocalAllocFromString(Caption)
  xType1.ulFlags = &H1&    '&H3&
  If Not Len(InitDir) = 0& Then
    CommonDLG_OpenPath_CurDir = LocalAllocFromString(InitDir & vbNullChar)
    End If
  xType1.lpfnCallback = CommonDLG_OpenPath_CallbackProc(-2&, 0&, AddressOf CommonDLG_OpenPath_CallbackProc, 0&)
  If IsUnicode Then
    xLong1 = SHBrowseForFolderW(xType1)
    Else
    xLong1 = SHBrowseForFolderA(xType1)
    End If
  If Not xLong1 = 0& Then
    If IsUnicode Then
      hWnd = SHGetPathFromIDListW(xLong1, ptrTemp)
      Else
      hWnd = SHGetPathFromIDListA(xLong1, ptrTemp)
      End If
    If Not hWnd = 0& Then
      CommonDLG_OpenPath = PeekS(ptrTemp)
      End If
    Call CoTaskMemFree(xLong1)
    End If
  If Not CommonDLG_OpenPath_CurDir = 0& Then
    Call LocalFree(CommonDLG_OpenPath_CurDir)
    CommonDLG_OpenPath_CurDir = 0&
    End If
  If Not xType1.lpszTitle = 0& Then Call LocalFree(xType1.lpszTitle)
  End Function

Private Function CommonDLG_OpenPath_CallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lData As Long) As Long
  On Error Resume Next
  If hWnd = -2& Then
    CommonDLG_OpenPath_CallbackProc = lParam
    Else
    Select Case uMsg
      Case 1&
        #If CommonDLG_OpenPath_CallbackHack Then
          uMsg = CommonDLG_CallbackProc_Init(hWnd)
          If Not uMsg = 0& Then
            If Not CommonDLG_OpenPath_CurDir = 0& Then
              Call LocalFree(CommonDLG_OpenPath_CurDir)
              End If
            CommonDLG_OpenPath_CurDir = uMsg
            End If
          #Else
          uMsg = CommonDLG_OpenPath_GetTreeView(hWnd)
          If Not uMsg = 0& Then
            Call ShowWindow(uMsg, 0&)
            Call SetWindowLong(uMsg, -16&, (GetWindowLong(uMsg, -16&) And &HFFFFFBF7) Or &H1020&)
            Call ShowWindow(uMsg, 5&)
            End If
          #End If
        If Not CommonDLG_OpenPath_CurDir = 0& Then
          If IsUnicode Then
            Call SendMessageW(hWnd, &H467&, 1&, ByVal CommonDLG_OpenPath_CurDir)
            Else
            Call SendMessageA(hWnd, &H466&, 1&, ByVal CommonDLG_OpenPath_CurDir)
            End If
          End If
      Case 2&
        If IsUnicode Then
          If SHGetPathFromIDListW(lParam, ByVal ptrTemp) = 1& Then
            Call SendMessageW(hWnd, &H468&, 0&, ByVal ptrTemp)
            End If
          ElseIf SHGetPathFromIDListA(lParam, ByVal ptrTemp) = 1& Then
          Call SendMessageA(hWnd, &H464&, 0&, ByVal ptrTemp)
          End If
        '#If (CommonDLG_FlagA And &H30&) = &H30& Then
        #If CommonDLG_OpenPath_CallbackHack Then
          CommonDLG_CallbackProc_Change hWnd, PeekS(ptrTemp)
          #End If
      End Select
    CommonDLG_OpenPath_CallbackProc = 0&
    End If
  End Function

#If CommonDLG_OpenPath_CallbackHack Then
Public Function CommonDLG_OpenPath_GetTreeView(hWnd) As Long
#Else
Private Function CommonDLG_OpenPath_GetTreeView(hWnd) As Long
#End If
  CommonDLG_OpenPath_GetTreeView = GetWindow(hWnd, 5&)
  Do While (Not (CommonDLG_OpenPath_GetTreeView = 0&))
    If LCase(GetClassName(CommonDLG_OpenPath_GetTreeView)) = "systreeview32" Then
      Exit Do
      End If
    CommonDLG_OpenPath_GetTreeView = GetWindow(CommonDLG_OpenPath_GetTreeView, 2&)
    Loop
  End Function

Public Function CreateDialogIndirectParam(ByVal ResDialogOrID As Variant, ByVal hWndParent As Long, ByVal lpDialogFunc As Long, ByVal dwInitParam As Long, Optional ByVal hModule As Long) As Long
  Dim xChar1 As String

  #If LoadResEx_SetLanguageFile Then
    xChar1 = LoadResEx_Data(ResDialogOrID, 5, LoadResEx_LanguageFile_hModule)
    #Else
    xChar1 = LoadResEx_Data(ResDialogOrID, 5, App.hInstance)
    #End If
  If Not Len(xChar1) = 0& Then
    If hModule = 0& Then
      #If InIDE And Not CustomClassesInDialogs And LoadResEx_SetThemeFile Then
        hModule = LoadResEx_ThemeFile_hModule
        If hModule = 0& Then hModule = App.hInstance
        #ElseIf InIDE And Not CustomClassesInDialogs And LoadResEx_SetLanguageFile Then
        hModule = LoadResEx_LanguageFile_hModule
        If hModule = 0& Then hModule = App.hInstance
        #Else
        hModule = App.hInstance
        #End If
      End If
    If IsUnicode Then
      CreateDialogIndirectParam = CreateDialogIndirectParamW(hModule, xChar1, hWndParent, lpDialogFunc, dwInitParam)
      Else
      CreateDialogIndirectParam = CreateDialogIndirectParamA(hModule, xChar1, hWndParent, lpDialogFunc, dwInitParam)
      End If
    End If
  End Function

Public Function CreateDirectoryEx(ByVal FullPath As String) As Boolean
  Dim xChar1 As String
  Dim xLong1 As Long
  
  xLong1 = InStr(FullPath, "\")
  If Not xLong1 = 0& Then
    FullPath = FullPath & "\"
    xChar1 = Left(FullPath, xLong1 - 1&)
    FullPath = Mid(FullPath, xLong1 + 1&)
    Do
      xLong1 = InStr(FullPath, "\")
      If xLong1 = 0& Then
        Exit Do
        Else
        xChar1 = xChar1 & "\" & Left(FullPath, xLong1 - 1&)
        If IsUnicode Then
          Call CreateDirectoryW(StrPtr(xChar1), 0&)
          Else
          Call CreateDirectoryA(xChar1, 0&)
          End If
        FullPath = Mid(FullPath, xLong1 + 1&)
        End If
      Loop
    CreateDirectoryEx = ((GetFileAttributes(xChar1) And 16&) = 16&)
    End If
  End Function

Public Function CreateFontIndirect(lpLogFont As LOGFONT) As Long
  Dim xChar1 As String

  xChar1 = lpLogFont.FontName & String(33&, vbNullChar)
  If IsUnicode Then
    Call RtlMoveMemory(ByVal VarPtr(lpLogFont.lfFaceName(0)), ByVal StrPtr(xChar1), 66&)
    CreateFontIndirect = CreateFontIndirectW(VarPtr(lpLogFont))
    Else
    Call RtlMoveMemory(ByVal VarPtr(lpLogFont.lfFaceName(0)), ByVal xChar1, 33&)
    CreateFontIndirect = CreateFontIndirectA(VarPtr(lpLogFont))
    End If
  End Function

Public Function CreateFontIndirectEx(ByVal lpLogFont As Long) As Long
  If IsUnicode Then
    CreateFontIndirectEx = CreateFontIndirectW(lpLogFont)
    Else
    CreateFontIndirectEx = CreateFontIndirectA(lpLogFont)
    End If
  End Function

Public Function ctSSLayer_LoadVB(ParamArray CustomDLLFilenames()) As Long
  Dim xLong1 As Long
  '1=ok/versionid, -1=no dll, 0=incompatible
  
  For xLong1 = 0& To UBound(CustomDLLFilenames())
    hModul = LoadLibrary(CStr(CustomDLLFilenames(xLong1)))
    If Not hModul = 0& Then Exit For
    Next
  
  If hModul = 0& Then
    ctSSLayer_LoadVB = -1&
    Else
    xLong1 = GetProcAddress(hModul, "ctSSLayer_Version")
    If xLong1 = 0& Then
      Call FreeLibrary(hModul)
      ctSSLayer_LoadVB = 0&
      Else
      ctSSLayer_LoadVB = CallFunction_Fast(xLong1, LayerVersionID)
      If ctSSLayer_LoadVB = 0& Then
        Call FreeLibrary(hModul)
        Else
        ctSSLayer_CanUseItemInt = GetProcAddress(hModul, "ctSSLayer_CanUseItem")
        If IsUnicode Then
          #If ctSSLayer_Devices Then
            ctSSLayer_GetDeviceNameInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceNameW")
            ctSSLayer_GetDeviceSSLIDInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceSSLIDW")
            #End If
          #If ctSSLayer_GetInfoString Then
            ctSSLayer_GetInfoStringInt = GetProcAddress(hModul, "ctSSLayer_GetInfoStringW")
            #End If
          ctSSLayer_LoadSongInt = GetProcAddress(hModul, "ctSSLayer_LoadSongW")
          #If ctSSLayer_ReadSongInfo Then
            ctSSLayer_ReadSongInfoInt = GetProcAddress(hModul, "ctSSLayer_ReadSongInfoW")
            #End If
          Else
          #If ctSSLayer_Devices Then
            ctSSLayer_GetDeviceNameInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceNameA")
            ctSSLayer_GetDeviceSSLIDInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceSSLIDA")
            #End If
          #If ctSSLayer_GetInfoString Then
            ctSSLayer_GetInfoStringInt = GetProcAddress(hModul, "ctSSLayer_GetInfoStringA")
            #End If
          ctSSLayer_LoadSongInt = GetProcAddress(hModul, "ctSSLayer_LoadSongA")
          #If ctSSLayer_ReadSongInfo Then
            ctSSLayer_ReadSongInfoInt = GetProcAddress(hModul, "ctSSLayer_ReadSongInfoA")
            #End If
          End If
        #If ctSSLayer_GetPosition Then
          ctSSLayer_GetPositionInt = GetProcAddress(hModul, "ctSSLayer_GetPosition")
          #End If
        #If ctSSLayer_Spectrum Then
          ctSSLayer_GetSpectrumInt = GetProcAddress(hModul, "ctSSLayer_GetSpectrum")
          #End If
        #If ctSSLayer_LoadSongAbort Then
          ctSSLayer_LoadSongAbortInt = GetProcAddress(hModul, "ctSSLayer_LoadSongAbort")
          #End If
        #If ctSSLayer_LoadSongFinished Then
          ctSSLayer_LoadSongFinishedInt = GetProcAddress(hModul, "ctSSLayer_LoadSongFinished")
          #End If
        ctSSLayer_LoadSongPlayInt = GetProcAddress(hModul, "ctSSLayer_LoadSongPlay")
        #If ctSSLayer_MusicGetPattern Then
          ctSSLayer_MusicGetPatternInt = GetProcAddress(hModul, "ctSSLayer_MusicGetPattern")
          #End If
        #If ctSSLayer_MusicGetPatterns Then
          ctSSLayer_MusicGetPatternsInt = GetProcAddress(hModul, "ctSSLayer_MusicGetPatterns")
          #End If
        #If ctSSLayer_MusicHasFinished Then
          ctSSLayer_MusicHasFinishedInt = GetProcAddress(hModul, "ctSSLayer_MusicHasFinished")
          #End If
        #If ctSSLayer_MusicTime Then
          ctSSLayer_MusicTimeInt = GetProcAddress(hModul, "ctSSLayer_MusicTime")
          #End If
        #If ctSSLayer_SeekSong Then
          ctSSLayer_SeekSongInt = GetProcAddress(hModul, "ctSSLayer_SeekSong")
          #End If
        #If ctSSLayer_SetPause Then
          ctSSLayer_SetPauseInt = GetProcAddress(hModul, "ctSSLayer_SetPause")
          #End If
        #If ctSSLayer_SetVolume Then
          ctSSLayer_SetVolumeInt = GetProcAddress(hModul, "ctSSLayer_SetVolume")
          #End If
        #If ctSSLayer_GetSongLength Then
          ctSSLayer_SongLengthInt = GetProcAddress(hModul, "ctSSLayer_SongLength")
          #End If
        ctSSLayer_UnloadSongInt = GetProcAddress(hModul, "ctSSLayer_UnloadSong")
        End If
      End If
    End If
  End Function

Public Sub ctSSLayer_UnLoadVB()
  If Not hModul = 0& Then
    Call CallFunction_Indirect(hModul, "ctSSLayer_DllRelease")
    Call FreeLibrary(hModul)
    hModul = 0&
    End If
  End Sub

Public Function ctSSLayer_CanUseItem(ByVal Index As Long) As Long
  ctSSLayer_CanUseItem = CallFunction_Fast(ctSSLayer_CanUseItemInt, Index)
  End Function

Public Sub ctSSLayer_Close(ByVal Fast As Long)
  Call CallFunction_Indirect(hModul, "ctSSLayer_Close", Fast)
  End Sub

#If ctSSLayer_GetInfoString Then
  Public Function ctSSLayer_GetInfoString(ByVal Index As Long) As String
    ctSSLayer_GetInfoString = PeekS(CallFunction_Fast(ctSSLayer_GetInfoStringInt, Index))
    End Function
  #End If

#If ctSSLayer_GetPosition Then
  Public Function ctSSLayer_GetPosition(ByVal SongPointer As Long) As Long
    ctSSLayer_GetPosition = CallFunction_Fast(ctSSLayer_GetPositionInt, SongPointer)
    End Function
  #End If

Public Function ctSSLayer_Init(ByVal OutputDeviceID As Long, ByVal hWnd As Long, ByVal UseCDDA As Long, ByVal UseJitterCorrection As Long) As Long
  ctSSLayer_Init = CallFunction_Indirect(hModul, "ctSSLayer_Init", OutputDeviceID, hWnd, UseCDDA, UseJitterCorrection)
  End Function

Public Function ctSSLayer_LoadSong(ByVal Mode As Long, ByVal Filename As String, ByVal Flags As Long) As Long
  Dim xLong1 As Long

  If IsUnicode Then
    ctSSLayer_LoadSong = CallFunction_Fast(ctSSLayer_LoadSongInt, Mode, StrPtr(Filename), Flags)
    Else
    xLong1 = LocalAllocFromString(Filename)
    If Not xLong1 = 0& Then
      ctSSLayer_LoadSong = CallFunction_Fast(ctSSLayer_LoadSongInt, Mode, xLong1, Flags)
      Call LocalFree(xLong1)
      End If
    End If
  End Function

#If ctSSLayer_LoadSongAbort Then
  Public Sub ctSSLayer_LoadSongAbort(ByVal SongPointer As Long)
    Call CallFunction_Fast(ctSSLayer_LoadSongAbortInt, SongPointer)
    End Sub
  #End If

#If ctSSLayer_LoadSongFinished Then
  Public Function ctSSLayer_LoadSongFinished(ByVal SongPointer As Long) As Long
    ctSSLayer_LoadSongFinished = CallFunction_Fast(ctSSLayer_LoadSongFinishedInt, SongPointer)
    End Function
  #End If

Public Function ctSSLayer_LoadSongPlay(ByVal SongPointer As Long, ByVal Volume As Long, ByVal LoopSong As Long, ByVal Panning As Long, ByVal Paused As Long) As Long
  ctSSLayer_LoadSongPlay = CallFunction_Fast(ctSSLayer_LoadSongPlayInt, SongPointer, Volume, LoopSong, Panning, Paused)
  End Function

Public Function ctSSLayer_PreInit(ByVal hWnd As Long) As Long
  ctSSLayer_PreInit = CallFunction_Indirect(hModul, "ctSSLayer_PreInit", hWnd)
  End Function

#If ctSSLayer_SeekSong Then
  Public Function ctSSLayer_SeekSong(ByVal SongPointer As Long, ByVal SeekPosition As Long) As Long
    ctSSLayer_SeekSong = CallFunction_Fast(ctSSLayer_SeekSongInt, SongPointer, SeekPosition)
    End Function
  #End If

#If ctSSLayer_SetPause Then
  Public Sub ctSSLayer_SetPause(ByVal SongPointer As Long, ByVal Pause As Long)
    Call CallFunction_Fast(ctSSLayer_SetPauseInt, SongPointer, Pause)
    End Sub
  #End If

#If ctSSLayer_SetVolume Then
  Public Sub ctSSLayer_SetVolume(ByVal SongPointer As Long, ByVal Volume As Long)
    Call CallFunction_Fast(ctSSLayer_SetVolumeInt, SongPointer, Volume)
    End Sub
  #End If

#If ctSSLayer_GetSongLength Then
  Public Function ctSSLayer_SongLength(ByVal SongPointer As Long) As Long
    ctSSLayer_SongLength = CallFunction_Fast(ctSSLayer_SongLengthInt, SongPointer)
    End Function
  #End If

Public Sub ctSSLayer_UnloadSong(ByVal SongPointer As Long)
  Call CallFunction_Fast(ctSSLayer_UnloadSongInt, SongPointer)
  End Sub

Public Function ctSSLayer_GetDeviceFromSSLID(ByVal DeviceSSLID As String) As Long
  Dim xLong1 As Long

  If IsUnicode Then
    ctSSLayer_GetDeviceFromSSLID = CallFunction_Indirect(hModul, "ctSSLayer_GetDeviceFromSSLIDW", StrPtr(DeviceSSLID))
    Else
    xLong1 = LocalAllocFromString(DeviceSSLID)
    If Not xLong1 = 0& Then
      ctSSLayer_GetDeviceFromSSLID = CallFunction_Indirect(hModul, "ctSSLayer_GetDeviceFromSSLIDA", xLong1)
      Call LocalFree(xLong1)
      End If
    End If
  End Function

Public Function ctSSLayer_GetDeviceName(ByVal DeviceID As Long, ByRef Flags As Long) As String
  ctSSLayer_GetDeviceName = PeekS(CallFunction_Fast(ctSSLayer_GetDeviceNameInt, DeviceID, VarPtr(Flags)))
  End Function

Public Function ctSSLayer_GetDeviceSSLID(ByVal DeviceID As Long) As String
  ctSSLayer_GetDeviceSSLID = PeekS(CallFunction_Fast(ctSSLayer_GetDeviceSSLIDInt, DeviceID))
  End Function

#If ctSSLayer_RefreshDeviceList Then
  Public Function ctSSLayer_RefreshDeviceList(ByVal hWnd As Long)
    ctSSLayer_RefreshDeviceList = CallFunction_Indirect(hModul, "ctSSLayer_RefreshDeviceList", hWnd)
    End Function
  #End If

#If ctSSLayer_Spectrum Then
  Public Sub ctSSLayer_GetSpectrum(ByRef xSingleA1Array As Single, ByVal ArraySize As Long, ByVal SongPointer As Long, ByVal Stereo As Boolean)
    Call CallFunction_Fast(ctSSLayer_GetSpectrumInt, VarPtr(xSingleA1Array), ArraySize, SongPointer, -CLng(Stereo * 3&))
    End Sub
  #End If

#If ctSSLayer_SetEndCallback Then
  Public Sub ctSSLayer_SetEndCallback(ByVal hWnd As Long, ByVal Message As Long, ByVal wParam As Long)
    Call CallFunction_Indirect(hModul, "ctSSLayer_SetEndCallback", hWnd, Message, wParam)
    End Sub
  #End If

#If ctSSLayer_Spectrum Then
  Public Sub ctSSLayer_SetSpectrum(ByVal State As Long)
    Call CallFunction_Indirect(hModul, "ctSSLayer_SetSpectrum", State)
    End Sub
  #End If

#If ctSSLayer_UpdateCDDA Then
  Public Sub ctSSLayer_UpdateCDDA(ByVal UseCDDA As Long, ByVal UseJitterCorrection As Long)
    Call CallFunction_Indirect(hModul, "ctSSLayer_UpdateCDDA", UseCDDA, UseJitterCorrection)
    End Sub
  #End If

#If ctSSLayer_UpdateLooping Then
  Public Sub ctSSLayer_UpdateLooping(ByVal SongPointer As Long, ByVal LoopSong As Long)
    Call CallFunction_Indirect(hModul, "ctSSLayer_UpdateLooping", SongPointer, LoopSong)
    End Sub
  #End If

#If ctSSLayer_UpdatePanning Then
  Public Sub ctSSLayer_UpdatePanning(ByVal SongPointer As Long, ByVal Panning As Long)
    Call CallFunction_Indirect(hModul, "ctSSLayer_UpdatePanning", SongPointer, Panning)
    End Sub
  #End If

#If ctSSLayer_MusicGetPattern Then
  Public Function ctSSLayer_MusicGetPattern(ByVal SongPointer As Long) As Long
    ctSSLayer_MusicGetPattern = CallFunction_Fast(ctSSLayer_MusicGetPatternInt, SongPointer)
    End Function
  #End If

#If ctSSLayer_MusicGetPatterns Then
  Public Function ctSSLayer_MusicGetPatterns(ByVal SongPointer As Long) As Long
    ctSSLayer_MusicGetPatterns = CallFunction_Fast(ctSSLayer_MusicGetPatternsInt, SongPointer)
    End Function
  #End If

#If ctSSLayer_MusicHasFinished Then
  Public Function ctSSLayer_MusicHasFinished(ByVal SongPointer As Long) As Long
    ctSSLayer_MusicHasFinished = CallFunction_Fast(ctSSLayer_MusicHasFinishedInt, SongPointer)
    End Function
  #End If

#If ctSSLayer_MusicTime Then
  Public Function ctSSLayer_MusicTime(ByVal SongPointer As Long) As Long
    ctSSLayer_MusicTime = CallFunction_Fast(ctSSLayer_MusicTimeInt, SongPointer)
    End Function
  #End If

Public Function ctSSLayer_ReadSongInfo(ByVal SongPointer As Long, xSongInfo As ctSSLayerSongInfoStruct) As Boolean
  Dim xLongA1(13&) As Long

  ctSSLayer_ReadSongInfo = Not (CallFunction_Fast(ctSSLayer_ReadSongInfoInt, SongPointer, VarPtr(xLongA1(0))) = 0&)
  Call RtlMoveMemory(xSongInfo, ByVal VarPtr(xLongA1(0)), 36&)

  xSongInfo.Tag_Artist = PeekS(xLongA1(9&)) 'xType1.Tag_Artist)
  xSongInfo.Tag_Title = PeekS(xLongA1(10&)) 'xType1.Tag_Title)
  xSongInfo.Tag_Album = PeekS(xLongA1(11&)) 'xType1.Tag_Album)
  xSongInfo.IR_Name = PeekS(xLongA1(12&))
  xSongInfo.IR_URL = PeekS(xLongA1(13&))
  End Function

Public Function DoEventsEx_GetElapsedTime(ByVal FirstTickCountValue As Long) As Long
  Static xLong1 As Long
  xLong1 = GetTickCount And &H3FFFFFFF
  If xLong1 < FirstTickCountValue Then
    DoEventsEx_GetElapsedTime = xLong1 + &H40000000 - FirstTickCountValue
    Else
    DoEventsEx_GetElapsedTime = (xLong1 - FirstTickCountValue)
    End If
  End Function

Public Function DoEventsEx_GetTickCount() As Long
  DoEventsEx_GetTickCount = GetTickCount And &H3FFFFFFF
  If DoEventsEx_GetTickCount = 0 Then
    DoEventsEx_GetTickCount = &H3FFFFFFF
    End If
  End Function

Public Sub DoEventsEx(ByVal TimeIntervalMs As Long, Optional ByVal FirstTickValue As Long = -1&)
  Static xLong1 As Long

  If TimeIntervalMs > SleepValueHigh Or FirstTickValue = -1& Then
    If FirstTickValue = -1& Then
      FirstTickValue = GetTickCount And &H3FFFFFFF
      End If
    DoEventsEx_Sleep SleepValueHigh
    Do
      xLong1 = GetTickCount And &H3FFFFFFF
      If xLong1 < FirstTickValue Then
        xLong1 = TimeIntervalMs - (xLong1 + &H40000000 - FirstTickValue)
        Else
        xLong1 = TimeIntervalMs - (xLong1 - FirstTickValue)
        End If
      If xLong1 > 0& Then
        If xLong1 > SleepValueHigh Then xLong1 = SleepValueHigh
        DoEventsEx_Sleep xLong1
        Else
        Exit Do
        End If
      Loop
    Else
    DoEventsEx_Sleep TimeIntervalMs
    End If
  End Sub

Public Sub DoEventsEx_SleepPeriodical()
  Static xLong1 As Long
  Dim xLong2 As Long
  
  xLong2 = GetTickCount And &H3FFFFFFF
  If xLong2 < xLong1 Then
    If (xLong2 + &H40000000 > xLong1 + DoEventsEx_SleepPeriodical_Interval) Then
      GoTo ProcIt
      End If
    Else
    If (xLong2 > xLong1 + DoEventsEx_SleepPeriodical_Interval) Then
ProcIt:
      DoEventsEx_Sleep SleepValueLow
      xLong1 = GetTickCount And &H3FFFFFFF
      End If
    End If
  End Sub

Public Function DragQueryFileCount(ByVal hDrop As Long) As Long
  If IsUnicode Then
    DragQueryFileCount = DragQueryFileW(hDrop, -1&, 0&, 0&)
    Else
    DragQueryFileCount = DragQueryFileA(hDrop, -1&, 0&, 0&)
    End If
  End Function

Public Function DragQueryFile(ByVal hDrop As Long, ByVal Index As Long, ByRef ReturnString As String) As Boolean
  Dim xLong1 As Long
  
  ReturnString = ""
  If IsUnicode Then
    xLong1 = DragQueryFileW(hDrop, Index, ptrTemp, ptrTempSizeXW)
    Else
    xLong1 = DragQueryFileA(hDrop, Index, ptrTemp, ptrTempSizeX)
    End If
  If Not xLong1 = 0& Then
    ReturnString = PeekS(ptrTemp, xLong1)
    DragQueryFile = True
    End If
  End Function

Public Function DrawText(ByVal hdc As Long, ByVal lpStr As String, lpRect As RECT, ByVal wFormat As Long) As Long
  Dim xLong1 As Long
  
  xLong1 = Len(lpStr)
  If IsUnicode Then
    DrawText = DrawTextW(hdc, StrPtr(lpStr), xLong1, lpRect, wFormat)
    Else
    DrawText = DrawTextA(hdc, lpStr, xLong1, lpRect, wFormat)
    End If
  End Function

Public Function FindFirstChangeNotification(ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
  If IsUnicode Then
    FindFirstChangeNotification = FindFirstChangeNotificationW(StrPtr(lpPathName), bWatchSubtree, dwNotifyFilter)
    Else
    FindFirstChangeNotification = FindFirstChangeNotificationA(lpPathName, bWatchSubtree, dwNotifyFilter)
    End If
  End Function

Public Function FindFirstFile(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA, ByVal Attributes As VbFileAttribute) As Long
  lpFindFileData.dwFileAttributes = CLng(Attributes)
  If IsUnicode Then
    FindFirstFile = FindFirstFileW(StrPtr(lpFileName), lpFindFileData)
    Else
    FindFirstFile = FindFirstFileA(lpFileName, lpFindFileData)
    End If
  lpFindFileData.Filename = PeekS(VarPtr(lpFindFileData.Reserved_cFileName(0)), 260&)
  End Function

Public Function FindNextFile(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  If IsUnicode Then
    FindNextFile = FindNextFileW(hFindFile, lpFindFileData)
    Else
    FindNextFile = FindNextFileA(hFindFile, lpFindFileData)
    End If
  lpFindFileData.Filename = PeekS(VarPtr(lpFindFileData.Reserved_cFileName(0)), 260&)
  End Function

Public Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  If IsUnicode Then
    FindWindow = FindWindowW(StrPtr(lpClassName), StrPtr(lpWindowName))
    Else
    FindWindow = FindWindowA(lpClassName, lpWindowName)
    End If
  End Function

Public Function GetAddressOf(ByVal xLong1 As Long) As Long
  GetAddressOf = xLong1
  End Function

Public Function GetAPIPopupMenu(ByVal hWndCaller As Long, ByVal hMenu As Long, ByVal HWndControl As Long) As Long
  Dim xType1 As POINTAPI
  Dim xType2 As RECT
  Dim xLong1 As Long
  Dim xType4 As RECT
    
  Dim xMenuSize As POINTAPI
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
    
    'xControlMode: 10(-12 reserved) -> ListBox
    ' -1-> mouse
    ' 0 -> nospecial
    ' 1 -> centerclient
    ' 2 -> outsidecontrol
    
    '0=SingleSel?
    '1=extended?
    '2=checkboxmode?
  If Not hMenu = 0& Then
    xLong4 = CreateWindowEx(0, "STATIC", vbNullString, &H8000003, 0&, 0&, 32&, 32&, 0&, 0&, 0&)
    '&H8000000
    Call SetMenu(xLong4, hMenu)
    Call DrawMenuBar(xLong4)
    Call SetMenu(xLong4, 0&)
    Call DrawMenuBar(xLong4)
    
    xLong1 = GetMenuItemCount(hMenu)
    Call GetMenuItemRect(xLong4, hMenu, xLong1 - 1&, xType2)
    xMenuSize.x = xType2.Right
    xMenuSize.y = xType2.Bottom
    Call GetMenuItemRect(xLong4, hMenu, 0&, xType2)
    If Not hWndCaller = 0& Then Call DestroyWindow(xLong4)
    
    xMenuSize.x = xMenuSize.x - xType2.Left
    xMenuSize.y = xMenuSize.y - xType2.Top
    xMenuSize.x = xMenuSize.x + GetSystemMetrics(7&) * 2&
    xMenuSize.y = xMenuSize.y + GetSystemMetrics(8&) * 2&
    
    'Call SystemParametersInfoA(48&, 0&, xType2, 0&)
    'Call GetOptMonitorFromPoint((xType2.Left + xType2.Right) / 2&, (xType2.Top + xType2.Bottom) / 2&, xType2)
    If HWndControl = 0& Then
      'Debug.Print "1"
      Call WindowToCursorPos(xMenuSize, xType1)
      Call GetOptMonitorFromPoint(xType1.x, xType1.y, xType2)
      Else
      'Debug.Print "2"
      Call ClientToScreen(HWndControl, xType1)
      Call GetWindowRect(HWndControl, xType4)
      Call GetOptMonitorFromPoint((xType4.Left + xType4.Right) / 2&, (xType4.Top + xType4.Bottom) / 2&, xType2)
      xType4.Bottom = xType4.Bottom - xType4.Top
      
      'Call SystemParametersInfoA(48&, 0&, xType2, 0&)
      'Call GetOptMonitorFromPoint((xType2.Left + xType2.Right) / 2&, (xType2.Top + xType2.Bottom) / 2&, xType2)
      
      Select Case UCase(GetClassName(HWndControl))
        Case "LISTBOX"
          xLong1 = SendMessage(HWndControl, &H19F&, 0&, 0&) 'LB_GETCARETINDEX
          xLong3 = SendMessage(HWndControl, &H18E&, 0&, 0&) 'LB_GETTOPINDEX
          xLong2 = SendMessage(HWndControl, &H1A1&, 0&, 0&) 'LB_GETITEMHEIGHT
          
          If Not (xLong1 > xLong3 - 1& And xLong1 < xLong3 + (xType4.Bottom \ xLong2) - 1&) Then
            xLong3 = xLong1 - (xType4.Bottom \ xLong2 - 1&) \ 2&
            If xLong3 < 0 Then xLong3 = 0&
            Call SendMessage(HWndControl, &H197&, xLong3, 0&) 'LB_SETTOPINDEX
            End If
          xLong1 = xLong1 - xLong3
          'Stop
          If xType1.y + (xLong1 + 1.25) * xLong2 + xMenuSize.y > xType2.Bottom Then
            xType1.y = xType1.y - xMenuSize.y + (xLong1 - 0.25) * xLong2
            Else
            xType1.y = xType1.y + (xLong1 + 1.25) * xLong2
            End If
            
            ' center l/r
        xType4.Right = xType4.Right - xType4.Left
        If xType4.Right > xMenuSize.x Then
          xType1.x = xType1.x + (xType4.Right - xMenuSize.x) \ 2&
          End If
            
        Case Else
          xType1.y = xType4.Bottom / 4&
          If xType4.Top + xType4.Bottom - xType1.y + xMenuSize.y > xType2.Bottom Then
            xType1.y = xType4.Top + xType1.y - xMenuSize.y
            Else
            xType1.y = xType4.Top + xType4.Bottom - xType1.y
            End If
          xType1.x = (xType4.Right - xType4.Left) / 4
          If xType4.Left + xType1.x + xMenuSize.x > xType2.Right Then
            xType1.x = xType4.Right - xType1.x - xMenuSize.x
            Else
            xType1.x = xType4.Left + xType1.x
            End If
        
        'If (xControlType And &HFFFF&) = 0& Then
        '  If xType4.Bottom > xMenuSize.y Then
        '    xType1.y = xType1.y + (xType4.Bottom - xMenuSize.y) \ 2&
        '    End If
        '  End If
        End Select
      
      
      If xType1.x + xMenuSize.x > xType2.Right Then
        xType1.x = xType2.Right - xMenuSize.x
        End If
      If xType1.y + xMenuSize.y > xType2.Bottom Then
        xType1.y = xType2.Bottom - xMenuSize.y
        End If
      End If
    If xType1.x < xType2.Left Then xType1.x = xType2.Left
    If xType1.y < xType2.Top Then xType1.y = xType2.Top
    
    #If ToolTip Then
      ToolTip_DisableInt
      #End If
    If hWndCaller = 0& Then
      xLong2 = GetForegroundWindow()
      Call SetForegroundWindow(xLong4)
      DoEvents
      Call SetForegroundWindow(xLong4)
      GetAPIPopupMenu = TrackPopupMenuEx(hMenu, &H182&, xType1.x, xType1.y, xLong4, 0&)
      If Not (xLong2 = 0& Or GetAPIPopupMenu = 0&) Then
        Call SetForegroundWindow(xLong2)
        End If
      Call DestroyWindow(xLong4)
      Else
      GetAPIPopupMenu = TrackPopupMenuEx(hMenu, &H182&, xType1.x, xType1.y, hWndCaller, 0&)
      Call PostMessage(hWndCaller, 0&, 0&, 0&)
      End If
    #If ToolTip Then
      ToolTip_IsEnabledInt = True
      #End If
    End If
  End Function

Public Function GetDlgItemText(ByVal hDlg As Long, ByVal nIDDlgItem As Long) As String
  If IsUnicode Then
    hDlg = GetDlgItemTextW(hDlg, nIDDlgItem, ptrTemp, ptrTempSizeXW)
    Else
    hDlg = GetDlgItemTextA(hDlg, nIDDlgItem, ptrTemp, ptrTempSizeX)
    End If
  GetDlgItemText = PeekS(ptrTemp, hDlg)
  End Function

Public Function GetFileVersionField(ByVal FieldType As GetFileVersionField_Enum, Optional ByVal DefaultValue As String = "???") As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim hMem As Long
  Dim xChar1 As String
  Dim FieldStr As String

  xChar1 = AppBase()
  If IsUnicode Then
    xLong1 = GetFileVersionInfoSizeW(StrPtr(xChar1), xLong2)
    Else
    xLong1 = GetFileVersionInfoSizeA(xChar1, xLong2)
    End If
  If Not xLong1 = 0& Then
    hMem = LocalAlloc(&H40&, xLong1)
    If Not hMem = 0& Then
      If IsUnicode Then
        xLong1 = GetFileVersionInfoW(StrPtr(xChar1), xLong2, xLong1, ByVal hMem)
        Else
        xLong1 = GetFileVersionInfoA(xChar1, xLong2, xLong1, ByVal hMem)
        End If
      If Not xLong1 = 0& Then
        'xChar1 = VerQueryValue(hMem, CStr(FieldType))
        Select Case FieldType
          Case GetFileVersionField_Comments:         FieldStr = "Comments"
          Case GetFileVersionField_CompanyName:      FieldStr = "CompanyName"
          Case GetFileVersionField_FileDesc:         FieldStr = "FileDescription"
          Case GetFileVersionField_FileVersion:      FieldStr = "FileVersion"
          Case GetFileVersionField_InternalName:     FieldStr = "InternalName"
          Case GetFileVersionField_LegalCopyright:   FieldStr = "LegalCopyright"
          Case GetFileVersionField_LegalTrademarks:  FieldStr = "LegalTrademarks"
          Case GetFileVersionField_OriginalFilename: FieldStr = "OriginalFilename"
          Case GetFileVersionField_PrivateBuild:     FieldStr = "PrivateBuild"
          Case GetFileVersionField_ProductName:      FieldStr = "ProductName"
          Case GetFileVersionField_ProductVersion:   FieldStr = "ProductVersion"
          Case GetFileVersionField_SpecialBuild:     FieldStr = "SpecialBuild"
          Case Else: GoTo IncompatibleFieldType
          End Select
        If IsUnicode Then
          xChar1 = "\VarFileInfo\Translation"
          xLong3 = VerQueryValueW(ByVal hMem, StrPtr(xChar1), xLong1, xLong2)
          Else
          xLong3 = VerQueryValueA(ByVal hMem, "\VarFileInfo\Translation", xLong1, xLong2)
          End If
        If Not xLong3 = 0& And xLong2 > 3& Then
          xChar1 = Right("00000000" + LCase(Hex(PeekL(xLong1))), 8)
          FieldStr = "\StringFileInfo\" + Right(xChar1, 4&) + Left(xChar1, 4&) + "\" + FieldStr + vbNullChar
'          FieldStr = "\StringFileInfo\040904B0\" + FieldStr + vbNullChar
          If IsUnicode Then
            If Not VerQueryValueW(ByVal hMem, StrPtr(FieldStr), xLong1, xLong2) = 0& Then
              #If PeekS_Wide Then
                GetFileVersionField = PeekS_Wide(xLong1, xLong2)
                #Else
                GoTo PeekShared
                #End If
              End If
            ElseIf Not VerQueryValueA(ByVal hMem, FieldStr, xLong1, xLong2) = 0& Then
            #If PeekS_Ansi Then
              GetFileVersionField = PeekS_Ansi(xLong1, xLong2)
              #Else
PeekShared:
              GetFileVersionField = PeekS(xLong1, xLong2)
              #End If
            End If
          End If
IncompatibleFieldType:
        End If
      Call LocalFree(hMem)
      End If
    End If
  #If InIDE Then
    If Len(GetFileVersionField) = 0& Then GetFileVersionField = "<n/a in IDE>"
    #Else
    If Len(GetFileVersionField) = 0& Then GetFileVersionField = DefaultValue
    #End If
  End Function

Public Function GetFileAttributes(ByVal lpFileName As String) As Long
  If IsUnicode Then
    GetFileAttributes = GetFileAttributesW(StrPtr(lpFileName))
    Else
    GetFileAttributes = GetFileAttributesA(lpFileName)
    End If
  End Function

Public Function GetFullPathName(ByVal xChar1 As String) As String
  Dim xLong1 As Long
  
  If IsUnicode Then
    xLong1 = GetFullPathNameW(StrPtr(xChar1), ptrTempSizeXW, ptrTemp, 0&)
    Else
    xLong1 = GetFullPathNameA(xChar1, ptrTempSizeX, ptrTemp, 0&)
    End If
  If Not xLong1 = 0& And xLong1 < 256& Then
    GetFullPathName = PeekS(ptrTemp, xLong1)
    ElseIf Mid(xChar1, 2&, 2&) = ":\" Or Left(xChar1, 2&) = "\\" Then
    GetFullPathName = xChar1
    End If
  End Function

Public Function GetKeyNameText(ByVal lParam As Long) As String
  If IsUnicode Then
    lParam = GetKeyNameTextW(lParam, ptrTemp, ptrTempSizeXW)
    Else
    lParam = GetKeyNameTextA(lParam, ptrTemp, ptrTempSizeX)
    End If
  If Not lParam = 0& Then GetKeyNameText = PeekS(ptrTemp, lParam)
  End Function

Public Function GetSpecialFolderPath(ByVal nFolder As Long, ByVal SetBackSlash As Boolean) As String
  Dim xLong1 As Long
  Dim xLong2 As Long

  If SHGetSpecialFolderLocation(0&, nFolder, xLong1) = 0& Then
DoWithSHFolderDLL:
    If Not xLong1 = 0& Then
      If IsUnicode Then
        xLong2 = SHGetPathFromIDListW(xLong1, ptrTemp)
        Else
        xLong2 = SHGetPathFromIDListA(xLong1, ptrTemp)
        End If
      If Not xLong2 = 0& Then
        GetSpecialFolderPath = PeekS(ptrTemp)
        If Right(GetSpecialFolderPath, 1&) = "\" Then
          If Not SetBackSlash Then GetSpecialFolderPath = Left(GetSpecialFolderPath, Len(GetSpecialFolderPath) - 1&)
          ElseIf SetBackSlash Then
          GetSpecialFolderPath = GetSpecialFolderPath + "\"
          End If
        End If
      Call CoTaskMemFree(xLong1)
      End If
    Else
    On Error GoTo Er1
    If SHGetSpecialFolderLocationFromSHFolder(0&, nFolder, xLong1) = 0& Then
      On Error GoTo 0
      GoTo DoWithSHFolderDLL
      End If
Rs1:
    On Error GoTo 0
    End If
  Exit Function
  
Er1:
  Resume Rs1
  End Function

Public Function GetStrippedCommandLine() As String
  #If InIDE Then
    GetStrippedCommandLine = Command
    #Else
    Dim xLong1 As Long
    
    If IsUnicode Then
      xLong1 = GetCommandLineW
      Else
      xLong1 = GetCommandLineA
      End If
    If Not xLong1 = 0& Then
      GetStrippedCommandLine = PeekS(xLong1)
      If Left(GetStrippedCommandLine, 1&) = Chr(34) Then
        xLong1 = InStr(2&, GetStrippedCommandLine, Chr(34))
        Else
        xLong1 = InStr(GetStrippedCommandLine, " ")
        End If
      If xLong1 = 0& Then
        GetStrippedCommandLine = ""
        Else
        GetStrippedCommandLine = Trim(Mid(GetStrippedCommandLine, xLong1 + 1&))
        End If
      End If
    #End If
  End Function

Public Function GetTextOutWidth(ByVal hdc As Long, ByVal xString As String) As Long
  GetTextOutWidth = Len(xString)
  Call GetTextExtentPoint32Wide(hdc, StrPtr(xString), GetTextOutWidth, GetTextOutWidth_PointApi)
  GetTextOutWidth = GetTextOutWidth_PointApi.x
  End Function

Public Function GetWindowLong(ByVal hWnd As Long, ByVal nIndex As Long) As Long
  If IsUnicode Then
    GetWindowLong = GetWindowLongW(hWnd, nIndex)
    Else
    GetWindowLong = GetWindowLongA(hWnd, nIndex)
    End If
  End Function

Public Function GetWindowText(ByVal hWnd As Long) As String
  If IsUnicode Then
    hWnd = GetWindowTextW(hWnd, ByVal ptrTemp, ptrTempSizeXW)
    Else
    hWnd = GetWindowTextA(hWnd, ByVal ptrTemp, ptrTempSizeX)
    End If
  GetWindowText = PeekS(ptrTemp, hWnd)
  End Function

Public Function LoadLibrary(ByVal lpLibFileName As String) As Long
  If IsUnicode Then
    LoadLibrary = LoadLibraryW(StrPtr(lpLibFileName))
    Else
    LoadLibrary = LoadLibraryA(lpLibFileName)
    End If
  End Function

' -1 = lngfile (=true)
'  0 = intonly
Public Function LoadResEx_Data(ByVal resName As Variant, Optional ByVal resType As Variant = "BIN", Optional ByVal hModul As Long) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  Dim xChar2 As String
#If InIDE Then
  Dim xByteA1() As Byte
#End If
    
  If VarType(resName) = vbString Then
    xChar1 = resName
    Else
    xChar1 = "#" + CStr(Val(resName))
    End If
  If VarType(resType) = vbString Then
    xChar2 = resType
    Else
    xChar2 = "#" + CStr(Val(resType))
    End If
      
  If hModul = 0& Then
    hModul = App.hInstance
    End If

#If InIDE Then
  If hModul = App.hInstance Then
    On Error GoTo Er1:
    If Left(resName, 1&) = "#" Then resName = Val(Mid(resName, 2&))
    If Left(resType, 1&) = "#" Then resType = Val(Mid(resType, 2&))
    xByteA1() = LoadResData(resName, resType)
    xLong1 = UBound(xByteA1())
    If xLong1 > -1& Then
      xLong1 = xLong1 + 1&
      LoadResEx_Data = String(xLong1, vbNullChar)
      Call RtlMoveMemory(ByVal LoadResEx_Data, xByteA1(0), xLong1)
      End If
Rs1:
    On Error GoTo 0
    Exit Function
Er1:
    Resume Rs1
    End If
#End If


  xLong1 = FindResourceA(hModul, xChar1, xChar2)
  If Not xLong1 = 0& Then
    xLong2 = LoadResource(hModul, xLong1)
    If Not xLong2 = 0& Then
      xLong1 = SizeofResource(hModul, xLong1)
      If Not xLong1 = 0& Then
        hModul = LockResource(xLong2)
        If Not hModul = 0& Then
          LoadResEx_Data = String(xLong1, vbNullChar)
          Call RtlMoveMemory(ByVal LoadResEx_Data, ByVal hModul, xLong1)
          End If
        End If
      End If
    End If
  End Function

Private Function LoadResEx_Dialog_InternalProc(ByVal HWndDialog As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As LoadResEx_Dialog_DialogInfo
  
  If Msg = &H110& Then
    If Not lParam = 0& Then
      xLong1 = lParam
      Call RtlMoveMemory(xType1, ByVal lParam, LoadResEx_Dialog_DialogInfoSize)
      If Not xType1.xCallBackProc = 0& Then
        If IsUnicode Then
          LoadResEx_Dialog_InternalProc = CallWindowProcW(xType1.xCallBackProc, HWndDialog, Msg, wParam, lParam)
          Else
          LoadResEx_Dialog_InternalProc = CallWindowProcA(xType1.xCallBackProc, HWndDialog, Msg, wParam, lParam)
          End If
        If Not LoadResEx_Dialog_InternalProc = 0& Then
          LoadResEx_Dialog_InternalProc = GetDlgItem(HWndDialog, LoadResEx_Dialog_InternalProc)
          GoTo FocusFromProc
          End If
        End If
      If Not xType1.xButtonCtlID = 0& Then
        LoadResEx_Dialog_InternalProc = GetDlgItem(HWndDialog, xType1.xButtonCtlID)
        If Not LoadResEx_Dialog_InternalProc = 0& Then
FocusFromProc:
          If Not LoadResEx_Dialog_InternalProc = 0& Then
            SetFocusAPI LoadResEx_Dialog_InternalProc
            'Stop
            LoadResEx_Dialog_InternalProc = 0&
            Else
            LoadResEx_Dialog_InternalProc = 1&
            End If
          Else
          LoadResEx_Dialog_InternalProc = 1&
          End If
        End If
      Call SetWindowLong(HWndDialog, -21&, xLong1)
      End If
    Else
    xLong1 = GetWindowLong(HWndDialog, -21&)
    If Not xLong1 = 0& Then
      Call RtlMoveMemory(xType1, ByVal xLong1, LoadResEx_Dialog_DialogInfoSize)
      Select Case Msg
        Case &H10&
          If Not xType1.xEscBehaviour = LoadResEx_Dialog_Disabled Then
            GoTo lblEndDialog
            End If
        Case &H111& 'wm_command
          If lParam = 0& Then
            If wParam = 2& And Not xType1.xEscBehaviour = LoadResEx_Dialog_Disabled Then
'              Stop
              GoTo lblEndDialog
              End If
            Else
            If (GetWindowLong(lParam, -16&) And &HE&) = 0& Then
              If xType1.xCallBackProc = 0& Then
                xType1.xEscBehaviour = wParam
'                Stop
                GoTo lblEndDialog
                Else
                If IsUnicode Then
                  xLong1 = CallWindowProcW(xType1.xCallBackProc, HWndDialog, Msg, wParam, lParam)
                  Else
                  xLong1 = CallWindowProcA(xType1.xCallBackProc, HWndDialog, Msg, wParam, lParam)
                  End If
                If xLong1 = 1& Then
                  xType1.xEscBehaviour = wParam
'                  Stop
                  GoTo lblEndDialog
                  End If
                End If
              ElseIf Not xType1.xCallBackProc = 0& Then
              If IsUnicode Then
                Call CallWindowProcW(xType1.xCallBackProc, HWndDialog, Msg, wParam, lParam)
                Else
                Call CallWindowProcA(xType1.xCallBackProc, HWndDialog, Msg, wParam, lParam)
                End If
              End If
            End If
        End Select
      End If
    End If
  Exit Function

lblEndDialog:
  If Not xType1.xCallBackProc = 0& Then
    If IsUnicode Then
      Call CallWindowProcW(xType1.xCallBackProc, HWndDialog, &H12&, wParam, lParam)
      Else
      Call CallWindowProcA(xType1.xCallBackProc, HWndDialog, &H12&, wParam, lParam)
      End If
    End If
  Call EndDialog(HWndDialog, xType1.xEscBehaviour)
  End Function

' result (ButtonID etc), or 0/1
' DefaultButtonID = Control ID for focus
' CanEscapeControlID = Control ID (Result) if ESC pressed, LoadResEx_Dialog_Disabled (-1) to prevent ESC from closing dialog
Public Function LoadResEx_Dialog(ByVal hWndOwner As Long, ByVal ResDialogOrID As Variant, Optional DefaultButtonID As Long = 0&, Optional ByVal CanEscapeControlID As Long = LoadResEx_Dialog_Disabled, Optional ByVal CallBackProc As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As LoadResEx_Dialog_DialogInfo
    
  xType1.xCallBackProc = CallBackProc
  xType1.xEscBehaviour = CanEscapeControlID
  xType1.xButtonCtlID = DefaultButtonID
  xLong1 = LocalAlloc(0&, LoadResEx_Dialog_DialogInfoSize)
  If Not xLong1 = 0& Then
    Call RtlMoveMemory(ByVal xLong1, xType1, LoadResEx_Dialog_DialogInfoSize)
    LoadResEx_Dialog = DialogBoxIndirectParam(ResDialogOrID, hWndOwner, AddressOf LoadResEx_Dialog_InternalProc, xLong1)            ', ResDialogID)
    Call LocalFree(xLong1)
    End If
  End Function

Public Function LoadResEx_PagedDialog(ByVal hWndOwner As Long, ByVal ResDialogID As Long, ByVal ResDialogIDLast As Long, ByVal ResDialogIDStep As Long, Optional ByVal CallBackProc As Long, Optional ByVal CaptionID As Long = -1&) As Long ', Optional ByVal CallBackProcInit As Long)
  Dim xLong1 As Long
  Dim xMaxDialogPages As Long
  Dim xChar1 As String
  Dim xType1 As PROPSHEETHEADER
  Dim xLongA1() As Long
  Dim xLongA2() As Long
  Dim xTypeA1() As PROPSHEETPAGE

  xMaxDialogPages = (ResDialogIDLast - ResDialogID) \ ResDialogIDStep
  ReDim xLongA1(xMaxDialogPages)
  ReDim xLongA2(xMaxDialogPages)
  ReDim xTypeA1(xMaxDialogPages)
  
  xMaxDialogPages = 0&
  For xLong1 = ResDialogID To ResDialogIDLast Step ResDialogIDStep
    #If LoadResEx_SetLanguageFile Then
      xChar1 = LoadResEx_Data("#" + CStr(xLong1), "#5", LoadResEx_LanguageFile_hModule)
      #Else
      xChar1 = LoadResEx_Data("#" + CStr(xLong1), "#5")
      #End If
    
    If Not Len(xChar1) = 0& Then
      HackDialogResource ResDialogID, xChar1
      
      xLongA1(xMaxDialogPages) = LocalAlloc(0&, Len(xChar1))
      If Not xLongA1(xMaxDialogPages) = 0& Then
        Call RtlMoveMemory(ByVal xLongA1(xMaxDialogPages), ByVal xChar1, Len(xChar1))
        With xTypeA1(xMaxDialogPages)
          .Size = Len(xTypeA1(0))
            .Flags = &H1&
          #If InIDE And Not CustomClassesInDialogs And LoadResEx_SetThemeFile Then
            .hInstance = LoadResEx_ThemeFile_hModule
            #Else
            .hInstance = App.hInstance
            #End If
          .pfnDlgProc = CallBackProc
          .pResource = xLongA1(xMaxDialogPages)
          
          If IsUnicode Then
            xLongA2(xMaxDialogPages) = CreatePropertySheetPageW(xTypeA1(xMaxDialogPages))
            Else
            xLongA2(xMaxDialogPages) = CreatePropertySheetPageA(xTypeA1(xMaxDialogPages))
            End If
          If xLongA2(xMaxDialogPages) = 0& Then
            Call LocalFree(xLongA1(xMaxDialogPages))
            Else
            xMaxDialogPages = xMaxDialogPages + 1&
            End If
          End With
        End If
      End If
    Next
  If Not xMaxDialogPages = 0& Then
    ReDim Preserve xTypeA1(xMaxDialogPages - 1&)
    With xType1
      .dwSize = Len(xType1)
      .nPages = xMaxDialogPages
      .hInstance = App.hInstance
      .hWndParent = hWndOwner
      .phpage = VarPtr(xLongA2(0))
      #If LoadResEx_PagedDialog_NoContextHelpHook Then
        .pnfCallback = GetAddressOf(AddressOf LoadResEx_PagedDialog_NoContextHelpHook)
        #End If
      End With
    If CaptionID = -1& Then CaptionID = ResDialogID
    
    xType1.pszCaption = LocalAllocFromString(LoadResEx_String(CaptionID))
    If IsUnicode Then
      LoadResEx_PagedDialog = PropertySheetW(xType1)
      Else
      LoadResEx_PagedDialog = PropertySheetA(xType1)
      End If
    If Not xType1.pszCaption = 0& Then
      Call LocalFree(xType1.pszCaption)
      End If
    For xLong1 = 0& To xMaxDialogPages - 1&
      Call LocalFree(xLongA1(xLong1))
      Next
    End If
  End Function

#If LoadResEx_PagedDialog_NoContextHelpHook Then
  Private Function LoadResEx_PagedDialog_NoContextHelpHook(ByVal hWnd As Long, ByVal Msg As Long, ByVal lParam As Long) As Long
    Dim xLongA1(3) As Long

    If Msg = 2& Then
      Call RtlMoveMemory(ByVal VarPtr(xLongA1(0)), ByVal lParam, 16&)
      If (xLongA1(0) And &HFFFF&) = &HFFFF& Then
        xLongA1(3) = xLongA1(3) And &HFFFFDFFF
        Else
        xLongA1(0) = xLongA1(0) And &HFFFFDFFF
        End If
      Call RtlMoveMemory(ByVal lParam, ByVal VarPtr(xLongA1(0)), 16&)
      End If
    LoadResEx_PagedDialog_NoContextHelpHook = 1&
    End Function
  #End If

Public Sub LoadResEx_Dialog_Enable(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByVal Enable As Boolean)
  ControlID = GetDlgItem(DialogHWnd, ControlID)
  If Not ControlID = 0& Then
    Call EnableWindow(ControlID, -CLng(Enable))
    End If
  End Sub

Public Function LoadResEx_Dialog_SpinnerLong(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByRef Value As Long, Optional ByVal ReadFromDialog As Boolean = False, Optional ByVal Min As Long = -1&, Optional ByVal Max As Long = -1&) As Boolean
  ControlID = GetDlgItem(DialogHWnd, ControlID)
  If Not ControlID = 0& Then
    If ReadFromDialog Then
      ControlID = (SendMessage(ControlID, &H468&, 0&, 0&) And &HFFFF&)
      If Not (Max = -1& Or Min = -1&) Then
        If ControlID > Max Then
          ControlID = Max
          ElseIf ControlID < Min Then
          ControlID = Min
          End If
        End If
      If Not ControlID = Value Then
        Value = ControlID
        LoadResEx_Dialog_SpinnerLong = True
        End If
      Else
      If Not (Max = -1& Or Min = -1&) Then
        Call SendMessage(ControlID, &H465&, 0&, (Min * &H10000 + Max))
        Call SendMessage(ControlID, &H467&, 0&, Value)
        End If
      End If
    End If
  End Function

Public Sub LoadResEx_Dialog_ListFill(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByVal ResIDFirstString As Long, ByVal ResIDLastString As Long)
  ControlID = GetDlgItem(DialogHWnd, ControlID)
  If Not ControlID = 0& Then
    For ResIDFirstString = ResIDFirstString To ResIDLastString
      Call SendMessage_String(ControlID, &H143&, 0&, LoadResEx_String(ResIDFirstString))
      Next
    End If
  End Sub

Public Function LoadResEx_Dialog_ListIndex(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByRef Value As Long, Optional ByVal ReadFromDialog As Boolean = False) As Boolean
  ControlID = GetDlgItem(DialogHWnd, ControlID)
  If Not ControlID = 0& Then
    If ReadFromDialog Then
      ControlID = SendMessage(ControlID, &H188&, 0&, 0&)
      If Not ControlID = Value Then
        Value = ControlID
        LoadResEx_Dialog_ListIndex = True
        End If
      Else
      Call SendMessage(ControlID, &H186&, Value, 0&)
      End If
    End If
  End Function

Public Function LoadResEx_Dialog_ListIndexCB(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByRef Value As Long, Optional ByVal ReadFromDialog As Boolean = False) As Boolean
  ControlID = GetDlgItem(DialogHWnd, ControlID)
  If Not ControlID = 0& Then
    If ReadFromDialog Then
      ControlID = SendMessage(ControlID, &H147&, 0&, 0&)
      If Not ControlID = Value Then
        Value = ControlID
        LoadResEx_Dialog_ListIndexCB = True
        End If
      Else
      Call SendMessage(ControlID, &H14E&, Value, 0&)
      End If
    End If
  End Function

Public Sub LoadResEx_Dialog_ListIndexMS(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByVal Value As Long)
  ControlID = GetDlgItem(DialogHWnd, ControlID)
  If Not ControlID = 0& Then
    Call SendMessage(ControlID, &H185, 0&, -1&)
    Call SendMessage(ControlID, &H185, 1&, Value)
    Call SendMessage(ControlID, &H186, 1&, Value)
    Call SendMessage(ControlID, &H14E&, Value, 0&)
    End If
  End Sub

Public Function LoadResEx_Dialog_CheckBool(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByRef Value As Boolean, Optional ByVal ReadFromDialog As Boolean = False) As Boolean ', Optional ByVal Depency1ControlID As Long, Optional ByVal Depency1ControlID As Long) as boolean
  If ReadFromDialog Then
    If Not GetDlgItem(DialogHWnd, ControlID) = 0& Then
      LoadResEx_Dialog_CheckBool = CBool(IsDlgButtonChecked(DialogHWnd, ControlID))
      If LoadResEx_Dialog_CheckBool Xor Value Then
        Value = LoadResEx_Dialog_CheckBool
        LoadResEx_Dialog_CheckBool = True
        Else
        LoadResEx_Dialog_CheckBool = False
        End If
      End If
    Else
    Call CheckDlgButton(DialogHWnd, ControlID, -CLng(Value))
    End If
  End Function

Public Function LoadResEx_Menu(ByVal MenuID As Long) As Long
  #If LoadResEx_SetLanguageFile Then
    #If Unicode Then
      If IsUnicode Then
        LoadResEx_Menu = LoadMenuW(LoadResEx_LanguageFile_hModule, StrPtr("#" & CStr(MenuID)))
        Else
        LoadResEx_Menu = LoadMenuA(LoadResEx_LanguageFile_hModule, ByVal "#" & CStr(MenuID))
        End If
      #Else
      LoadResEx_Menu = LoadMenuA(LoadResEx_LanguageFile_hModule, ByVal "#" & CStr(MenuID))
      #End If
    #Else
    #If InIDE Then
      Dim xLong1 As Long
      Dim xChar1 As String
      Dim xByteA1() As Byte
      
      #If LoadResEx_SetLanguageFile Then
        xChar1 = LoadResEx_Data(MenuID, 4&, LoadResEx_LanguageFile_hModule)
        #Else
        xChar1 = LoadResEx_Data(MenuID, 4&, App.hInstance)
        #End If
      If Not Len(xChar1) = 0& Then
        On Error GoTo Er1:
        xByteA1() = LoadResData(MenuID, 4&)
        xLong1 = UBound(xByteA1())
        If xLong1 > -1& Then
          xLong1 = xLong1 + 1&
          #If Unicode Then
            If IsUnicode Then
              LoadResEx_Menu = LoadMenuInIDEW(xByteA1(0))
              Else
              LoadResEx_Menu = LoadMenuInIDEA(xByteA1(0))
              End If
            #Else
            LoadResEx_Menu = LoadMenuInIDEA(xByteA1(0))
            #End If
          End If
        End If
Rs1:
      On Error GoTo 0
      Exit Function

Er1:
      Resume Rs1
      
      
      #Else
      #If Unicode Then
        If IsUnicode Then
          LoadResEx_Menu = LoadMenuW(App.hInstance, StrPtr("#" & CStr(MenuID)))
          Else
          LoadResEx_Menu = LoadMenuA(App.hInstance, ByVal "#" & CStr(MenuID))
          End If
        #Else
        LoadResEx_Menu = LoadMenuA(App.hInstance, ByVal "#" & CStr(MenuID))
        #End If
      #End If
    #End If
  End Function

Public Sub LoadResEx_Menu_Add(ByVal hMenu As Long, ByVal MenuID As Long, ByVal Caption As String, Optional ByVal InsertAfter As Long = -1&)
  If Not hMenu = 0& Then
    If IsUnicode Then
      Call InsertMenuW(hMenu, InsertAfter, 0&, MenuID, StrPtr(Caption))
      Else
      Call InsertMenuA(hMenu, InsertAfter, 0&, MenuID, ByVal Caption)
      End If
    End If
  End Sub

Public Sub LoadResEx_Menu_AddSeperator(ByVal hMenu As Long, Optional ByVal MenuID As Long = 0&, Optional ByVal InsertAfter As Long = -1&)
  If Not hMenu = 0& Then
    If IsUnicode Then
      Call InsertMenuW(hMenu, InsertAfter, &H800&, MenuID, 0&)
      Else
      Call InsertMenuA(hMenu, InsertAfter, &H800&, MenuID, ByVal 0&)
      End If
    End If
  End Sub

Public Function LoadResEx_Menu_GetCaption(ByVal hMenu As Long, ByVal MenuID As Long) As String
  If IsUnicode Then
    MenuID = GetMenuStringW(hMenu, MenuID, ptrTemp, ptrTempSizeXW, 0&)
    Else
    MenuID = GetMenuStringA(hMenu, MenuID, ptrTemp, ptrTempSizeX, 0&)
    End If
  If Not MenuID = 0& Then LoadResEx_Menu_GetCaption = PeekS(ptrTemp, MenuID)
  End Function

Public Function LoadResEx_Menu_MakePopupMenu(ByRef hMenu As Long, Optional ByVal KeepAnyWay As Boolean = False) As Long
  If Not hMenu = 0& Then
    LoadResEx_Menu_MakePopupMenu = CreatePopupMenu()
    If LoadResEx_Menu_MakePopupMenu = 0& Then
      If Not KeepAnyWay Then
        DestroyMenu hMenu
        hMenu = 0&
        End If
      ElseIf IsUnicode Then
      Call InsertMenuW(LoadResEx_Menu_MakePopupMenu, -1&, &H410&, hMenu, ByVal 0&)
      Else
      Call InsertMenuA(LoadResEx_Menu_MakePopupMenu, -1&, &H410&, hMenu, ByVal 0&)
      End If
    End If
  End Function

Public Sub LoadResEx_Menu_SetCaption(ByVal hMenu As Long, ByVal MenuID As Long, ByVal Caption As String, Optional ByVal NewMenuID As Long = -1&)
  Dim xLong1 As Long
    
  If NewMenuID = -1& Then NewMenuID = MenuID
    
  xLong1 = GetMenuState(hMenu, MenuID, 0&)
  If Not xLong1 = -1& Then
    If IsUnicode Then
      Call ModifyMenuW(hMenu, MenuID, xLong1, NewMenuID, StrPtr(Caption))
      Else
      Call ModifyMenuA(hMenu, MenuID, xLong1, NewMenuID, Caption)
      End If
    End If
  End Sub

Public Function LoadResEx_Icon(ByVal ResID As Long, Optional ByVal DesiredSize As Long = 32&) As Long
  Dim xLong1 As Long

  #If LoadResEx_SetThemeFile Then
    For xLong1 = LoadResex_Caps_WinDIcon To 0& Step -1&
      If IconIDIsUseable(xLong1, LoadResex_Caps_WinDIcon) Then
        LoadResEx_Icon = LoadImageA(LoadResEx_ThemeFile_hModule, ByVal (ResID + xLong1), 1&, DesiredSize, DesiredSize, 0&)
        If Not LoadResEx_Icon = 0& Then Exit Function
        End If
      Next
    #End If

  For xLong1 = LoadResex_Caps_WinDIcon To 0& Step -1&
    If IconIDIsUseable(xLong1, LoadResex_Caps_WinDIcon) Then
      LoadResEx_Icon = LoadImageA(App.hInstance, ByVal (ResID + xLong1), 1&, DesiredSize, DesiredSize, 0&)
      If Not LoadResEx_Icon = 0& Then Exit Function
      End If
    Next

  #If InIDE And LoadResEx_SetLanguageFile Then
    For xLong1 = LoadResex_Caps_WinDIcon To 0& Step -1&
      If IconIDIsUseable(xLong1, LoadResex_Caps_WinDIcon) Then
        LoadResEx_Icon = LoadImageA(LoadResEx_LanguageFile_hModule, ByVal (ResID + xLong1), 1&, DesiredSize, DesiredSize, 0&)
        If Not LoadResEx_Icon = 0& Then Exit Function
        End If
      Next
    #End If
  End Function

Public Function LoadResEx_SetLanguageFile(Optional ByVal Filename As String, Optional ByVal IdentifyString As String) As Boolean
  If Not LoadResEx_LanguageFile_hModule = App.hInstance Then
    Call FreeLibrary(LoadResEx_LanguageFile_hModule)
    LoadResEx_LanguageFile_hModule = App.hInstance
    End If
  If Not Len(Filename) = 0& Then
    LoadResEx_LanguageFile_hModule = LoadLibrary(Filename)
    If LoadResEx_LanguageFile_hModule = 0& Then
      LoadResEx_LanguageFile_hModule = App.hInstance
      Else
      If Len(IdentifyString) = 0& Then
        LoadResEx_SetLanguageFile = True
        ElseIf LoadResEx_String(1&) = IdentifyString Then
        LoadResEx_SetLanguageFile = True
        Else
        FreeLibrary LoadResEx_LanguageFile_hModule
        LoadResEx_LanguageFile_hModule = App.hInstance
        End If
      End If
    End If
  End Function

Public Function LoadResEx_SetThemeFile(Optional ByVal Filename As String, Optional ByVal IdentifyString As String) As Boolean
  If Not LoadResEx_ThemeFile_hModule = App.hInstance Then
    Call FreeLibrary(LoadResEx_ThemeFile_hModule)
    LoadResEx_ThemeFile_hModule = App.hInstance
    End If
  If Not Len(Filename) = 0& Then
    LoadResEx_ThemeFile_hModule = LoadLibrary(Filename)
    If LoadResEx_ThemeFile_hModule = 0& Then
      LoadResEx_ThemeFile_hModule = App.hInstance
      Else
      If Len(IdentifyString) = 0& Then
        LoadResEx_SetThemeFile = True
        ElseIf LoadResEx_StringEx(LoadResEx_ThemeFile_hModule, 1&) = IdentifyString Then
        LoadResEx_SetThemeFile = True
        Else
        FreeLibrary LoadResEx_ThemeFile_hModule
        LoadResEx_ThemeFile_hModule = App.hInstance
        End If
      End If
    End If
  End Function

#If LoadResEx_String_Return_IsBlankResult Then
Public Function LoadResEx_String(ByVal ResID As Long, Optional ByRef IsBlankResult As Boolean) As String
#Else
Public Function LoadResEx_String(ByVal ResID As Long) As String
#End If
  Dim xLong1 As Long

  #If LoadResEx_String_Return_IsBlankResult Then
    IsBlankResult = False
    #End If
  If IsUnicode Then
    #If LoadResEx_SetLanguageFile Then
      xLong1 = LoadStringW(LoadResEx_LanguageFile_hModule, ResID, ptrTemp, ptrTempSizeXW)
      #Else
      xLong1 = LoadStringW(App.hInstance, ResID, ptrTemp, ptrTempSizeXW)
      #End If
    Else
    #If LoadResEx_SetLanguageFile Then
      xLong1 = LoadStringA(LoadResEx_LanguageFile_hModule, ResID, ptrTemp, ptrTempSizeX)
      #Else
      xLong1 = LoadStringA(App.hInstance, ResID, ptrTemp, ptrTempSizeX)
      #End If
    End If
  If xLong1 = 0& Then
    #If InIDE Then
      On Error GoTo Er1
      LoadResEx_String = LoadResString(ResID)
Rs1:
      On Error GoTo 0
      Exit Function
Er1:
      LoadResEx_String = "#" + CStr(ResID)
      #If LoadResEx_String_Return_IsBlankResult Then
        IsBlankResult = True
        #End If
      Resume Rs1
      #Else
      LoadResEx_String = "#" + CStr(ResID)
      #If LoadResEx_String_Return_IsBlankResult Then
        IsBlankResult = True
        #End If
      #End If
    Else
    LoadResEx_String = PeekS(ptrTemp, xLong1)
    End If
  End Function

#If Shell_NotifyIcon Then
Public Sub LoadResEx_WindowIcon(ByVal hWnd As Long, ByVal ResID As Long, Optional ByVal ptrTrayToUpdate As Long)
#Else
Public Sub LoadResEx_WindowIcon(ByVal hWnd As Long, ByVal ResID As Long)
#End If
  Dim Old1 As Long
  Dim Old2 As Long
  #If Shell_NotifyIcon Then
    Dim Old3 As Long
    Dim xType1 As NOTIFYICONDATA
    Dim xLong4 As Long
    #End If
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  #If LoadResEx_SetThemeFile Or (InIDE And LoadResEx_SetLanguageFile) Then
    Dim hModule As Long
    #End If
  '4th!
  
  Old1 = SendMessage(hWnd, &H80&, 0&, 0&)
  Old2 = SendMessage(hWnd, &H80&, 1&, 0&)
  #If Shell_NotifyIcon Then
    If Not ptrTrayToUpdate = 0& Then
      Call RtlMoveMemory(xType1, ByVal ptrTrayToUpdate, 24&)
      Old3 = xType1.hIcon
      End If
    #End If
  If Not ResID = -1& Then
    #If LoadResEx_SetThemeFile Then
      #If (InIDE And LoadResEx_SetLanguageFile) Then
        If LoadResEx_ThemeFile_hModule = App.hInstance Then
          hModule = LoadResEx_LanguageFile_hModule
          Else
          hModule = LoadResEx_ThemeFile_hModule
          End If
        #Else
        hModule = LoadResEx_ThemeFile_hModule
        #End If
      #ElseIf (InIDE And LoadResEx_SetLanguageFile) Then
      hModule = LoadResEx_LanguageFile_hModule
      #End If
ReLoop:
    For xLong1 = LoadResex_Caps_WinDIcon To 0& Step -1&
      If IconIDIsUseable(xLong1, LoadResex_Caps_WinDIcon) Then

        #If LoadResEx_SetThemeFile Or (InIDE And LoadResEx_SetLanguageFile) Then
          xLong2 = LoadImageA(hModule, ByVal (ResID + xLong1), 1&, 16&, 16&, 0&)
          xLong3 = LoadImageA(hModule, ByVal (ResID + xLong1 + 15), 1&, 32&, 32&, 0&)
          #Else
          xLong2 = LoadImageA(App.hInstance, ByVal (ResID + xLong1), 1&, 16&, 16&, 0&)
          xLong3 = LoadImageA(App.hInstance, ByVal (ResID + xLong1 + 15), 1&, 32&, 32&, 0&)
          #End If
        If xLong2 = 0& Then
          If Not xLong3 = 0& Then xLong2 = xLong3: GoTo UpdateMain
          Else
          If xLong3 = 0& Then xLong3 = xLong2
UpdateMain:
          Call SendMessage(hWnd, &H80&, 0&, xLong2)
          Call SendMessage(hWnd, &H80&, 1&, xLong3)
          
          'If Not (Old1 = 0&) Then Call DestroyIcon(Old1)
          'If Not (Old2 = Old1 Or Old2 = 0&) Then Call DestroyIcon(Old2)
          
          #If Shell_NotifyIcon Then
            If Not ptrTrayToUpdate = 0& Then
              If IconIDIsUseable(xLong1, LoadResex_Caps_TrayIcon) Then
                GoTo RealUpdateTrayPre
                Else
                For xLong3 = xLong1 - 1& To 0& Step -1&
                  If IconIDIsUseable(xLong3, LoadResex_Caps_TrayIcon) Then
                    #If LoadResEx_SetThemeFile Or (InIDE And LoadResEx_SetLanguageFile) Then
                      xLong4 = LoadImageA(hModule, ByVal (ResID + xLong3), 1&, 16&, 16&, 0&)
                      #Else
                      xLong4 = LoadImageA(App.hInstance, ByVal (ResID + xLong3), 1&, 16&, 16&, 0&)
                      #End If
                    If Not xLong4 = 0& Then GoTo RealUpdateTray
                    End If
                  Next
RealUpdateTrayPre:
                xLong4 = xLong2
RealUpdateTray:
                xType1.hIcon = xLong4
                Call RtlMoveMemory(ByVal ptrTrayToUpdate, xType1, 24&)
                If Not xType1.Reserved_cbsize = 0& Then Call Shell_NotifyIconEx(1&, ptrTrayToUpdate)
                End If
              End If
            'AndClearTray
            #End If
          GoTo FoundIcon
          End If
        End If
      Next

    #If LoadResEx_SetThemeFile Then
      If Not hModule = App.hInstance Then
        #If (InIDE And LoadResEx_SetLanguageFile) Then
          If hModule = LoadResEx_ThemeFile_hModule And Not hModule = LoadResEx_LanguageFile_hModule Then
            hModule = LoadResEx_LanguageFile_hModule
            GoTo ReLoop
            End If
          #End If
        hModule = App.hInstance
        GoTo ReLoop
        End If
      #ElseIf (InIDE And LoadResEx_SetLanguageFile) Then
      If Not hModule = App.hInstance Then
        hModule = App.hInstance
        GoTo ReLoop
        End If
      #End If
    End If

FoundIcon:
  If Not (Old1 = 0&) Then Call DestroyIcon(Old1)
  If Not (Old2 = Old1 Or Old2 = 0&) Then Call DestroyIcon(Old2)
  #If Shell_NotifyIcon Then
    'AndClearTray:
    If Not (Old3 = Old1 Or Old3 = 0&) Then Call DestroyIcon(Old3)
    #End If
  End Sub

Public Function MapVirtualKey(ByVal wCode As Long, ByVal wMapType As Long) As Long
  If IsUnicode Then
    MapVirtualKey = MapVirtualKeyW(wCode, wMapType)
    Else
    MapVirtualKey = MapVirtualKeyA(wCode, wMapType)
    End If
  End Function

Public Function PeekL(ByVal ptrMem As Long) As Long
  Call RtlMoveMemory(ByVal VarPtr(PeekL), ByVal ptrMem, 4&)
  End Function

Public Function PeekS(ByVal ptrChar As Long, Optional ByVal MaxLength As Long = -1&) As String
  Dim xLong1 As Long

  If Not ptrChar = 0& Then
    If MaxLength = -1& Then MaxLength = &HFFFF&
    If IsUnicode Then
      xLong1 = lstrlenW(ptrChar)
      If xLong1 > MaxLength Then xLong1 = MaxLength
      PeekS = String(xLong1 + 1&, vbNullChar)
      Call lstrcpynW(StrPtr(PeekS), ptrChar, xLong1 + 1&)
      Else
      xLong1 = lstrlenA(ptrChar)
      If xLong1 > MaxLength Then xLong1 = MaxLength
      PeekS = String(xLong1 + 1&, vbNullChar)
      Call lstrcpynA(PeekS, ptrChar, xLong1 + 1&)
      End If
    PeekS = Left(PeekS, xLong1)
    End If
  End Function

Public Function PeekS_Ansi(ByVal ptrChar As Long, Optional ByVal MaxLength As Long = -1&) As String
  Dim xLong1 As Long
  
  If Not ptrChar = 0& Then
    If MaxLength = -1& Then MaxLength = &HFFFF&
    xLong1 = lstrlenA(ptrChar)
    If xLong1 > MaxLength Then xLong1 = MaxLength
    PeekS_Ansi = String(xLong1 + 1&, vbNullChar)
    Call lstrcpynA(PeekS_Ansi, ptrChar, xLong1 + 1&)
    PeekS_Ansi = Left(PeekS_Ansi, xLong1)
    End If
  End Function

Public Function PeekS_Wide(ByVal ptrChar As Long, Optional ByVal MaxLength As Long = -1&) As String
  Dim xLong1 As Long

  If Not ptrChar = 0& Then
    If MaxLength = -1& Then MaxLength = &HFFFF&
    xLong1 = lstrlenW(ptrChar)
    If xLong1 > MaxLength Then xLong1 = MaxLength
    If IsUnicode Then
      PeekS_Wide = String(xLong1 + 1&, vbNullChar)
      Call lstrcpynW(StrPtr(PeekS_Wide), ptrChar, xLong1 + 1&)
      PeekS_Wide = Left(PeekS_Wide, xLong1)
      Else
      PeekS_Wide = String(xLong1, vbNullChar)
      Call RtlMoveMemory(ByVal StrPtr(PeekS_Wide), ByVal ptrChar, xLong1 * 2&)
      End If
    End If
  End Function

Public Sub PokeS(ByVal ptrMem As Long, ByVal xChar1 As String, ByVal MaxSize As Long, Optional ByVal NullByteExtraReserved As Boolean = False)
  Dim xLong1 As Long
  'Dim xLong2 As Long
  
  xLong1 = Len(xChar1)
  MaxSize = MaxSize - 1& - CLng(NullByteExtraReserved)
  If xLong1 > MaxSize Then
    xChar1 = Left(xChar1, MaxSize)
    xLong1 = MaxSize
    Else
    xLong1 = xLong1 + 1&
    End If
  xChar1 = xChar1 & vbNullChar
  If IsUnicode Then
    Call RtlMoveMemory(ByVal ptrMem, ByVal StrPtr(xChar1), xLong1 * 2&)
    Else
    Call RtlMoveMemory(ByVal ptrMem, ByVal xChar1, xLong1)
    End If
  End Sub

Public Function RegCreateKeyEx(ByVal HKEY As Long, ByVal lpSubKey As String, ByRef phkResult As Long) As Boolean
  Dim xLong1 As Long
  If IsUnicode Then
    RegCreateKeyEx = (RegCreateKeyExW(HKEY, StrPtr(lpSubKey), 0&, "", 0&, 2&, 0&, phkResult, xLong1) = 0&)
    Else
    RegCreateKeyEx = (RegCreateKeyExA(HKEY, lpSubKey, 0&, "", 0&, 2&, 0&, phkResult, xLong1) = 0&)
    End If
  End Function

Public Function RegDeleteKey(ByVal HKEY As Long, ByVal lpSubKey As String) As Long
  If IsUnicode Then
    RegDeleteKey = RegDeleteKeyW(HKEY, StrPtr(lpSubKey))
    Else
    RegDeleteKey = RegDeleteKeyA(HKEY, lpSubKey)
    End If
  End Function

Public Sub RegDeleteValue(ByVal HKEY As Long, ByVal lpValueName As String)
  If IsUnicode Then
    Call RegDeleteValueW(HKEY, StrPtr(lpValueName))
    Else
    Call RegDeleteValueA(HKEY, lpValueName)
    End If
  End Sub

Public Function RegEnumKey(ByVal HKEY As Long, ByVal dwIndex As Long, ByRef ReturnString As String) As Boolean
  ReturnString = ""
  If IsUnicode Then
    RegEnumKey = (RegEnumKeyW(HKEY, dwIndex, ptrTemp, ptrTempSizeXW) = 0&)
    Else
    RegEnumKey = (RegEnumKeyA(HKEY, dwIndex, ptrTemp, ptrTempSizeX) = 0&)
    End If
  If RegEnumKey Then ReturnString = PeekS(ptrTemp, ptrTempSizeXW)
  End Function

Public Function RegisterClassEx(pcWndClassEx As WNDCLASSEX, ByVal lpfnWndProc As Long) As Boolean
  pcWndClassEx.Reserved_lpszClassName = LocalAllocFromString(pcWndClassEx.ClassName)
  pcWndClassEx.cbSize = 48&
  pcWndClassEx.hInstance = App.hInstance
  
  If Not pcWndClassEx.Reserved_lpszClassName = 0& Then
    pcWndClassEx.lpfnWndProc = lpfnWndProc
    If IsUnicode Then
      RegisterClassEx = Not (RegisterClassExW(pcWndClassEx) = 0&)
      Else
      RegisterClassEx = Not (RegisterClassExA(pcWndClassEx) = 0&)
      End If
    LocalFree pcWndClassEx.Reserved_lpszClassName
    End If
  End Function

Public Sub UnregisterClass(ByVal lpClassName As String)
  If IsUnicode Then
    Call UnregisterClassW(StrPtr(lpClassName), App.hInstance)
    Else
    Call UnregisterClassA(lpClassName, App.hInstance)
    End If
  End Sub

Public Function RegisterFileTypes_GetRegistered(ByVal FileType As String, ByVal ProgramCaption As String, Optional ByRef IsDefaultRegistered As Boolean) As Boolean
  Dim xLong1 As Long
  Dim xBool1 As Boolean
  Dim xChar1 As String
  Dim xChar3 As String
  
  FileType = LCase(FileType)
  If RegOpenKeyEx(&H80000000, "." + FileType, 1&, xLong1) Then
    xBool1 = RegQueryValueEx_String(xLong1, "", xChar1)
    Call RegCloseKey(xLong1)
    End If
  
  If xBool1 Then
    xChar3 = xChar1
    If RegOpenKeyEx(&H80000000, xChar1 + "\Shell\" + ProgramCaption + "\Command", 1&, xLong1) Then
      If RegQueryValueEx_String(xLong1, "", xChar1) Then
        RegisterFileTypes_GetRegistered = (LCase(xChar1) = Chr(34&) & LCase(AppBase) & Chr(34&) & " " & Chr(34&) & "%1" & Chr(34&))
        End If
      Call RegCloseKey(xLong1)
      If RegOpenKeyEx(&H80000000, xChar3 + "\Shell", 1&, xLong1) Then
        If RegQueryValueEx_String(xLong1, "", xChar1) Then
          IsDefaultRegistered = (LCase(xChar1) = LCase(ProgramCaption))
          End If
        Call RegCloseKey(xLong1)
        End If
      End If
    End If
  End Function

Public Function RegisterFileTypes_RemoveRegistered(ByVal FileType As String, ByVal ProgramCaption As String, Optional ByVal DefaultActionBackupCaption As String) As Boolean
  'returns 0 if found itself's deficon
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xBool1 As Boolean
  Dim xChar1 As String
  Dim xChar3 As String
  
  
  FileType = LCase(FileType)
  If RegOpenKeyEx(&H80000000, "." + FileType, 1&, xLong1) Then
    xBool1 = RegQueryValueEx_String(xLong1, "", xChar1)
    Call RegCloseKey(xLong1)
    End If
  
  If xBool1 Then
    '1/2?
    If RegOpenKeyEx(&H80000000, "", 0&, xLong1) Then
      Call RegDeleteKey(xLong1, xChar1 + "\Shell\" + ProgramCaption)
      If RegOpenKeyEx(&H80000000, xChar1 + "\Shell", 8&, xLong2) Then
        xLong3 = CLng(RegEnumKey(xLong2, 0&, xChar3))   '= 259& Then
        Call RegCloseKey(xLong2)
        If xLong3 = 0& Then
          If Not Len(xChar1) = 0& Then
            If Asc(xChar1) > 34& Or Asc(xChar1) = 33& Then
              Call RegDeleteKey(xLong1, xChar1 + "\Shell")
              End If
            End If
          End If
        End If
      Call RegCloseKey(xLong1)
      End If
    
    If Not Len(DefaultActionBackupCaption) = 0& Then
      If RegOpenKeyEx(&H80000000, xChar1 + "\Shell", 3&, xLong1) Then
        If RegQueryValueEx_String(xLong1, DefaultActionBackupCaption, xChar3) Then
          Call RegSetValueEx_String(xLong1, "", xChar3)
          Call RegDeleteValue(xLong1, DefaultActionBackupCaption)
          End If
        End If
      End If
    
    If RegOpenKeyEx(&H80000000, xChar1 + "\DefaultIcon", 1&, xLong1) Then
      If RegQueryValueEx_String(xLong1, "", xChar3) Then
        xLong3 = 0
        Do
          xLong2 = InStr(xLong3 + 1, xChar3, ",")
          If xLong2 = 0 Then Exit Do
          xLong3 = xLong2
          Loop
        If Not xLong3 = 0 Then
          xChar3 = Left(xChar3, xLong3 - 1)
          End If
        If LCase(xChar3) = LCase(AppBase) Then
          xBool1 = False
          End If
        End If
      Call RegCloseKey(xLong1)
      End If
    If Not xBool1 Then
      If RegOpenKeyEx(&H80000000, "", 2&, xLong1) Then
        Call RegDeleteKey(xLong1, xChar1 + "\DefaultIcon")
        RegisterFileTypes_RemoveRegistered = True
        Call RegCloseKey(xLong1)
        End If
      End If
    If RegOpenKeyEx(&H80000000, xChar1 + "\Shell", 3&, xLong1) Then
      If RegQueryValueEx_String(xLong1, "", xChar3) Then
        If xChar3 = ProgramCaption Then
          Call RegDeleteValue(xLong1, "")
          End If
        End If
      Call RegCloseKey(xLong1)
      End If
    End If
  End Function

Public Function RegisterFileTypes_SetRegistered(ByVal FileType As String, ByVal GlobalFileType As String, ByVal ProgramCaption As String, ByVal OpeningCaption As String, Optional ByVal Description As String = vbNullChar, Optional ByVal Parameters As String = "", Optional ByVal IconIndex As Long = -1&, Optional ByVal AsDefaultRegistered As Boolean = False, Optional ByVal PassiveRegistration As Boolean = True, Optional ByVal DefaultActionBackupCaption As String) As Boolean
  Dim xLong1 As Long
  Dim xBool1 As Boolean
  Dim xChar1 As String
  Dim xChar2 As String
  
  FileType = LCase(FileType)
  If PassiveRegistration Then
    If RegOpenKeyEx(&H80000000, "." + FileType, 1&, xLong1) Then
      If RegQueryValueEx_String(xLong1, "", xChar1) Then
        GlobalFileType = xChar1
        xBool1 = True
        End If
      Call RegCloseKey(xLong1)
      End If
    End If
  
  If Not xBool1 Then
    If RegCreateKeyEx(&H80000000, "." + FileType, xLong1) Then
      Call RegSetValueEx_String(xLong1, "", GlobalFileType)
      Call RegCloseKey(xLong1)
      End If
    End If
  
  If (Not xBool1 Or AsDefaultRegistered) And Not Description = Chr(0) Then
    If RegCreateKeyEx(&H80000000, GlobalFileType, xLong1) Then
      Call RegSetValueEx_String(xLong1, "", Description)
  '    RegisterFileTypes_SetRegistered = True
      Call RegCloseKey(xLong1)
      End If
    End If
  
  xChar2 = LCase(AppBase)
  If Not AsDefaultRegistered Then
    '1/2?
    If RegOpenKeyEx(&H80000000, GlobalFileType + "\DefaultIcon", 0&, xLong1) Then
      Call RegCloseKey(xLong1)
      xBool1 = False
      Else
      xBool1 = True
      End If
    End If
  If (AsDefaultRegistered Or xBool1 And Not IconIndex = -1&) Then
    If RegCreateKeyEx(&H80000000, GlobalFileType + "\DefaultIcon", xLong1) Then
      xChar1 = xChar2 & "," & CStr(IconIndex)
      Call RegSetValueEx_String(xLong1, "", xChar1)
      RegisterFileTypes_SetRegistered = True
      Call RegCloseKey(xLong1)
      End If
    End If
  
  If AsDefaultRegistered Then
    If Not Len(DefaultActionBackupCaption) = 0& Then
      If RegOpenKeyEx(&H80000000, GlobalFileType + "\Shell", 3&, xLong1) Then
        If Not RegQueryValueEx_String(xLong1, DefaultActionBackupCaption, xChar1) Then
          If RegQueryValueEx_String(xLong1, "", xChar1) Then
            Call RegSetValueEx_String(xLong1, DefaultActionBackupCaption, xChar1)
            End If
          End If
        End If
      End If
    If RegCreateKeyEx(&H80000000, GlobalFileType + "\Shell", xLong1) Then
      Call RegSetValueEx_String(xLong1, "", ProgramCaption)
      Call RegCloseKey(xLong1)
      End If
    ElseIf Not Len(DefaultActionBackupCaption) = 0& Then
    If RegOpenKeyEx(&H80000000, GlobalFileType + "\Shell", 3&, xLong1) Then
      If RegQueryValueEx_String(xLong1, DefaultActionBackupCaption, xChar1) Then
        Call RegSetValueEx_String(xLong1, "", xChar1)
        Call RegDeleteValue(xLong1, DefaultActionBackupCaption)
        End If
      End If
    End If
  
  If RegCreateKeyEx(&H80000000, GlobalFileType + "\Shell\" + ProgramCaption, xLong1) Then
    Call RegSetValueEx_String(xLong1, "", OpeningCaption)
    Call RegCloseKey(xLong1)
    End If
  If RegCreateKeyEx(&H80000000, GlobalFileType + "\Shell\" + ProgramCaption + "\Command", xLong1) Then
    xChar1 = Chr(34) + xChar2 + Chr(34) + " " + Chr(34) + "%1" + Chr(34)
    If Not Parameters = "" Then
      xChar1 = xChar1 + " " + Parameters
      End If
    Call RegSetValueEx_String(xLong1, "", xChar1)
    Call RegCloseKey(xLong1)
    End If
  End Function

Public Function RegOpenKeyEx(ByVal HKEY As Long, ByVal lpSubKey As String, ByVal samDesired As Long, ByRef phkResult As Long) As Boolean
  If IsUnicode Then
    RegOpenKeyEx = (RegOpenKeyExW(HKEY, StrPtr(lpSubKey), 0&, samDesired, phkResult) = 0&)
    Else
    RegOpenKeyEx = (RegOpenKeyExA(HKEY, lpSubKey, 0&, 0&, phkResult) = 0&)
    End If
  End Function

Public Function RegQueryValueEx_String(ByVal HKEY As Long, ByVal lpValueName As String, ByRef ReturnString As String) As Boolean
  Dim xLong1 As Long
  Dim xLong2 As Long

  ReturnString = ""
  xLong1 = ptrTempSizeX
  If IsUnicode Then
    RegQueryValueEx_String = (RegQueryValueExW(HKEY, ByVal StrPtr(lpValueName), 0&, VarPtr(xLong2), ByVal ptrTemp, xLong1) = 0&)
    xLong1 = xLong1 / 2&
    Else
    RegQueryValueEx_String = (RegQueryValueExA(HKEY, lpValueName, 0&, VarPtr(xLong2), ByVal ptrTemp, xLong1) = 0&)
    End If
  If RegQueryValueEx_String And xLong1 > 1& And xLong2 = 1& Then
    ReturnString = PeekS(ptrTemp, xLong1 - 1&)
    Else
    RegQueryValueEx_String = False
    End If
  End Function

Public Sub RegSetValueEx_String(ByVal HKEY As Long, ByVal lpValueName As String, ByVal lpString As String)
  Dim xLong1 As Long
  
  xLong1 = Len(lpString) + 1&
  If IsUnicode Then
    Call RegSetValueExW(HKEY, StrPtr(lpValueName), 0&, 1&, ByVal StrPtr(lpString), xLong1 * 2&)
    Else
    Call RegSetValueExA(HKEY, lpValueName, 0&, 1&, ByVal lpString, xLong1)
    End If
  End Sub

Public Sub RemovableDevices_RegisterAll(ByVal hWnd As Long)
  Dim xLong1 As Long
  Dim xLong2 As Long
  
#If Unicode Then
  If IsUnicode Then
#End If
    xLong1 = GetLogicalDrives()
    For xLong2 = 2& To 25&
      If (xLong1 And (2& ^ xLong2)) Then
        Select Case GetDriveTypeA(Chr(65& + xLong2) & ":")
          Case 2&, 5&
            Call RemovableDevices_Register(hWnd, xLong2)
          End Select
        End If
      Next
#If Unicode Then
    End If
#End If
  End Sub

Public Function RemovableDevices_UnregisterAll() As Long
  Dim xLong1 As Long
  
  For xLong1 = 2& To 25&
    Call RemovableDevices_Unregister(xLong1)
    Next
  End Function

Public Function RemovableDevices_ResolveDriveID(ByVal lParam As Long)
  Dim xType1 As DEV_BROADCAST_HANDLE

'Stop
  RemovableDevices_ResolveDriveID = -1&
  Call RtlMoveMemory(xType1, ByVal lParam, 40&)
  For lParam = 2& To 25&
    If xType1.dbch_hdevnotify = RemovableDevices_Handle(lParam) Then
      RemovableDevices_ResolveDriveID = lParam
      Exit For
      End If
    Next
  End Function

Public Sub SetDlgItemText(ByVal DialogHWnd As Long, ByVal ControlID As Long, ByVal Text As String)
  If IsUnicode Then
    Call SetDlgItemTextW(DialogHWnd, ControlID, ByVal StrPtr(Text))
    Else
    Call SetDlgItemTextA(DialogHWnd, ControlID, Text)
    End If
  End Sub

Public Function ShellExecute(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Boolean
  If IsUnicode Then
    hWnd = ShellExecuteW(hWnd, StrPtr(lpOperation), StrPtr(lpFile), StrPtr(lpParameters), StrPtr(lpDirectory), nShowCmd)
    Else
    hWnd = ShellExecuteA(hWnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
    End If
  ShellExecute = (hWnd > 32& Or hWnd < 0&)
  End Function

#If LoadResEx_WindowIcon Then
  Public Sub Shell_NotifyIconEx(ByVal dwMessage As Long, ByVal lpData As Long)
    If IsUnicode Then
      If dwMessage = 1& And Shell_NotifyIconW(dwMessage, ByVal lpData) = 0& Then
        Call Shell_NotifyIconW(2&, ByVal lpData)
        Call Shell_NotifyIconW(0&, ByVal lpData)
        End If
      Else
      If dwMessage = 1& And Shell_NotifyIconA(dwMessage, ByVal lpData) = 0& Then
        Call Shell_NotifyIconA(2&, ByVal lpData)
        Call Shell_NotifyIconA(0&, ByVal lpData)
        End If
      End If
    End Sub
  #End If

Public Sub Shell_NotifyIcon(ByVal dwMessage As Long, lpData As NOTIFYICONDATA)
  Call PokeS(VarPtr(lpData.Reserved_szTip(0)), Replace(lpData.ToolTip, "&", "&&"), 64&, True)
#If LoadResEx_WindowIcon Then
  lpData.Reserved_cbsize = 88& - 64& * CLng(IsUnicode)
  Call Shell_NotifyIconEx(dwMessage, VarPtr(lpData))
  If dwMessage = 2& Then lpData.Reserved_cbsize = 0&
#Else
  If IsUnicode Then
    lpData.Reserved_cbsize = 88& + 64&
    If dwMessage = 1& And Shell_NotifyIconW(dwMessage, lpData) = 0& Then
      Call Shell_NotifyIconW(2&, lpData)
      Call Shell_NotifyIconW(0&, lpData)
      End If
    Else
    lpData.Reserved_cbsize = 88&
    If dwMessage = 1& And Shell_NotifyIconA(dwMessage, lpData) = 0& Then
      Call Shell_NotifyIconA(2&, lpData)
      Call Shell_NotifyIconA(0&, lpData)
      End If
    End If
#End If
  End Sub

Public Function SHFileOperation(lpFileOp As SHFILEOPSTRUCT) As Long
  lpFileOp.Reserved_pFrom = LocalAllocFromString(lpFileOp.From)
  If Not lpFileOp.Reserved_pFrom = 0& Then
    If IsUnicode Then
      SHFileOperation = SHFileOperationW(lpFileOp)
      Else
      SHFileOperation = SHFileOperationA(lpFileOp)
      End If
    LocalFree lpFileOp.Reserved_pFrom
    End If
  End Function

Public Function ShutdownWindowsEx(ByVal Mode As ShutDownWindowsEx_Mode) As Boolean
  Call AquirePrivilege("SeShutdownPrivilege")
  Select Case Mode
    Case SDWE_Shutdown
      ShutdownWindowsEx = Not (ExitWindowsEx(9&, 0&) = 0&)
    Case SDWE_Hibernate
      On Error Resume Next
      ShutdownWindowsEx = SetSystemPowerState(1&, 0&)
      On Error GoTo 0
    Case SDWE_Standby
      On Error Resume Next
      ShutdownWindowsEx = SetSystemPowerState(0&, 0&)
      On Error GoTo 0
    Case SDWE_MonitorsOff
      ShutdownWindowsEx = SendMessageA(-1&, &H112&, &HF170&, ByVal 1&)
    End Select
  End Function

Public Function SendMessage_String(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
  If IsUnicode Then
    SendMessage_String = SendMessageW(hWnd, Msg, wParam, ByVal StrPtr(lParam))
    Else
    SendMessage_String = SendMessageA(hWnd, Msg, wParam, ByVal lParam)
    End If
  End Function

Public Function SetWindowLong(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  If IsUnicode Then
    SetWindowLong = SetWindowLongW(hWnd, nIndex, dwNewLong)
    Else
    SetWindowLong = SetWindowLongA(hWnd, nIndex, dwNewLong)
    End If
  End Function

Public Sub SetWindowText(ByVal hWnd As Long, ByVal Caption As String)
  If IsUnicode Then
    Call SetWindowTextW(hWnd, StrPtr(Caption))
    Else
    Call SetWindowTextA(hWnd, Caption)
    End If
  End Sub

Public Sub TextOut(ByVal hdc As Long, ByVal xString As String, Optional ByVal PosX As Long, Optional ByVal PosY As Long)
  Dim xLong1 As Long
  
  xLong1 = Len(xString)
  Call TextOutWide(hdc, PosX, PosY, StrPtr(xString), xLong1)
  End Sub

Public Function TrackListBox(ByVal hWndCaller As Long, ByVal hWndListBox As Long, ByVal y As Long, ByVal AlwaysMenu As Boolean, ByVal MenuHandle As Long, ByVal ListMode As Long) As Integer
  'flags:
  ' 0=alwaysmenu
  ' 1=menuifselected etc
  ' 2=
  ' 1=Menu if out of bounds or empty
  ' 2=SingleSel or checkboxmode
  ' 4=NoProcessSelection
  Dim xLong1 As Long
  
  xLong1 = SendMessage(hWndListBox, &H1A9&, 0&, (&H10000 * y))
  
  If (xLong1 And &HFFFF0000) = 0& And Not SendMessage(hWndListBox, &H18B&, 0&, 0&) = 0& Then
    xLong1 = xLong1 And &HFFFF&
    If ListMode = 1& Then
      If SendMessage(hWndListBox, &H187&, xLong1, 0&) = 0& Then
        Call SendMessage(hWndListBox, &H185, 0&, -1&)
        Call SendMessage(hWndListBox, &H185, 1&, xLong1)
        End If
      Else
      If Not SendMessage(hWndListBox, &H188&, 0&, 0&) = xLong1 Then
        If ListMode = 2& Then
          Call SendMessage(hWndListBox, &H19E&, xLong1, 0&)
          Else
          Call SendMessage(hWndListBox, &H186&, xLong1, 0&)
          End If
        End If
      End If
    
    If MenuHandle = 0& Then
      TrackListBox = xLong1
      Else
      TrackListBox = GetAPIPopupMenu(hWndCaller, MenuHandle, 0&)
      End If
    Else
    If AlwaysMenu And Not MenuHandle = 0& Then
      TrackListBox = GetAPIPopupMenu(hWndCaller, MenuHandle, 0&)
      Else
      TrackListBox = -1&
      End If
    End If
  End Function

Public Function TxtFile_ReadLine(ByVal hTxtFileIn As Long, ByRef xLine As String) As Boolean
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType1 As TxtFileReadStruct

  xLine = ""
  If Not hTxtFileIn = 0& Then
    Call RtlMoveMemory(xType1, ByVal hTxtFileIn, TxtFileReadStructLen)
    If Not (xType1.hMem = 0& Or xType1.hMemPos = xType1.hMemEnd) Then
      xLong1 = CallWindowProcA(StrStrW_CrLf_Exe, 0&, 0&, xType1.hMemPos, 0&)
      If xLong1 = 0& Then
        Call LocalFree(xType1.hMem)
        xType1.hMem = 0&
        GoTo FailReWriteStruct
        Else
        xLong2 = xLong1
        UIntSubUInt xLong2, xType1.hMemPos
        If Not xLong2 = 0& Then
          xLine = String(xLong2 / 2&, vbNullChar)
          Call RtlMoveMemory(ByVal StrPtr(xLine), ByVal xType1.hMemPos, xLong2)
          End If
        UIntAddUInt xLong1, 4&
        xType1.hMemPos = xLong1
        TxtFile_ReadLine = True
FailReWriteStruct:
        Call RtlMoveMemory(ByVal hTxtFileIn, xType1, TxtFileReadStructLen)
        End If
      End If
    End If
  End Function

Public Function TxtFile_GetEncoding(ByRef hTxtFile As Long) As TxtFile_EncodingEnum
  Dim xType1 As TxtFileReadStruct

  If Not hTxtFile = 0& Then
    Call RtlMoveMemory(xType1, ByVal hTxtFile, TxtFileReadStructLen)
    If Not xType1.hMem = 0& Then
      TxtFile_GetEncoding = xType1.Encoding
      End If
    End If
  End Function

Public Function TxtFile_SetEncoding(ByVal hTxtFileIn As Long, ByVal Encoding As TxtFile_EncodingEnum, Optional ByVal ResetPosition As Boolean) As Boolean
  Dim xType1 As TxtFileReadStruct
  Dim xType2 As TxtFileReadStruct
  Dim hMemMB As Long
  Dim xSizeOrg As Long
  Dim xSizeNew As Long
  Dim xLong1 As Long
  'Const FindCRLF As String = vbCrLf

  If Not hTxtFileIn = 0& Then
    Call RtlMoveMemory(xType1, ByVal hTxtFileIn, TxtFileReadStructLen)
    If Not xType1.hMem = 0& Then
      If xType1.Encoding = Encoding Then
        TxtFile_SetEncoding = True
        ElseIf xType1.Encoding = TxtFile_EncodingEnum.CP_ACP And IsUnicode Then
        'ElseIf xType1.Encoding = TxtFile_EncodingEnum.CP_ACP Then
        If Encoding = TxtFile_EncodingEnum.CP_UTF8 Then
          xSizeOrg = xType1.hMemEnd
          UIntSubUInt xSizeOrg, xType1.hMem
          xSizeOrg = xSizeOrg / 2&
          hMemMB = LocalAlloc(0&, xSizeOrg + 2&)
          If Not hMemMB = 0& Then
            If WideCharToMultiByte(0&, 0&, ByVal xType1.hMem, xSizeOrg, ByVal hMemMB, xSizeOrg + 1&, ByVal 0&, ByVal 0&) = xSizeOrg Then
              xSizeNew = MultiByteToWideChar(Encoding, 0&, ByVal hMemMB, xSizeOrg, 0&, 0&)
              If Not xSizeNew = 0& Then
                xType2.hMem = LocalAlloc(0&, xSizeNew * 2& + 8&)
                If Not xType2.hMem = 0& Then
                  If ResetPosition Or xType1.hMemPos = xType1.hMem Then
                    xType2.hMemPos = xType2.hMem
                    Else
                    xLong1 = xType1.hMemPos
                    UIntSubUInt xLong1, xType1.hMem
                    xLong1 = xLong1 / 2&
                    xType2.hMemPos = MultiByteToWideChar(Encoding, 0&, ByVal hMemMB, xLong1, 0&, 0&)
                    UIntAddUInt xType2.hMemPos, xType2.hMem
                    End If
                  xLong1 = MultiByteToWideChar(Encoding, 0&, ByVal hMemMB, xSizeOrg, ByVal xType2.hMem, xSizeNew + 1&)
                  If xLong1 = xSizeNew Then
                    xType2.Encoding = Encoding
                    xType2.hMemEnd = xType2.hMem
                    xSizeNew = xSizeNew * 2&
                    UIntAddUInt xType2.hMemEnd, xSizeNew
                    Call LocalFree(xType1.hMem)
                    Call RtlMoveMemory(ByVal hTxtFileIn, xType2, TxtFileReadStructLen)
                    Call RtlMoveMemory(ByVal xType2.hMemEnd, ByVal StrPtr(vbCrLf), 4&)
                    UIntAddUInt xType2.hMemEnd, 4&
                    Call RtlMoveMemory(ByVal xType2.hMemEnd, ByVal StrPtr(vbNullChar), 2&)
                    TxtFile_SetEncoding = True
                    GoTo Success
                    End If
                  Call LocalFree(xType2.hMem)
Success:
                  End If
                End If
              End If
            Call LocalFree(hMemMB)
            End If
          End If
        End If
      End If
    End If
  End Function

Public Function TxtFile_WriteCreate(ByVal Filename As String) As Long
  If IsUnicode Then
    TxtFile_WriteCreate = TxtFile_WriteCreateEx(Filename, CP_WINUNICODE, True)
    Else
    TxtFile_WriteCreate = TxtFile_WriteCreateEx(Filename, CP_ACP, False)
    End If
  End Function

Public Function TxtFile_WriteCreateEx(ByVal Filename As String, ByVal Encoding As TxtFile_EncodingEnum, ByVal ByteOrderMark As Boolean) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType1 As TxtFileWriteStruct

  xType1.hFile = CreateFile(Filename, CreateAlwaysNew, FILE_WRITE)
  If Not xType1.hFile = -1& Then
    If Not SetEndOfFile(xType1.hFile) = 0& Then
      If ByteOrderMark Then
        If Encoding = TxtFile_EncodingEnum.CP_WINUNICODE Then
          xLong1 = &HFEFF&
          If Not WriteFile(xType1.hFile, ByVal VarPtr(xLong1), 2&, xLong2, 0&) = 0& Then
            If (xLong2 = 2&) Then
              GoTo Success
              End If
            End If
          ElseIf Encoding = TxtFile_EncodingEnum.CP_UTF8 Then
          xLong1 = &HBFBBEF
          If Not WriteFile(xType1.hFile, ByVal VarPtr(xLong1), 3&, xLong2, 0&) = 0& Then
            If (xLong2 = 3&) Then
              GoTo Success
              End If
            End If
          ElseIf Encoding = TxtFile_EncodingEnum.CP_ACP Then
          GoTo Success
          End If
        Else
Success:
        TxtFile_WriteCreateEx = LocalAlloc(0&, TxtFileWriteStructLen)
        If Not TxtFile_WriteCreateEx = 0& Then
          xType1.Encoding = Encoding
          Call RtlMoveMemory(ByVal TxtFile_WriteCreateEx, xType1, TxtFileWriteStructLen)
          Exit Function
          End If
        End If
      End If
    Call CloseHandle(xType1.hFile)
    End If
  End Function

Public Sub TxtFile_WriteClose(ByRef hTxtFileOut As Long)
  Dim xType1 As TxtFileWriteStruct

  If Not hTxtFileOut = 0& Then
    Call RtlMoveMemory(xType1, ByVal hTxtFileOut, TxtFileWriteStructLen)
    If Not xType1.hFile = -1& Then
      Call SetEndOfFile(xType1.hFile)
      Call CloseHandle(xType1.hFile)
      End If
    Call LocalFree(hTxtFileOut)
    hTxtFileOut = 0&
    End If
  End Sub

Public Function TxtFile_WriteLine(ByVal hTxtFileOut As Long, ByVal xLine As String) As Boolean
  TxtFile_WriteLine = TxtFile_WriteString(hTxtFileOut, xLine + vbCrLf)
  End Function

Public Function TxtFile_WriteAppend(ByVal Filename As String) As Long
  If IsUnicode Then
    TxtFile_WriteAppend = TxtFile_WriteAppendEx(Filename, CP_WINUNICODE, True)
    Else
    TxtFile_WriteAppend = TxtFile_WriteAppendEx(Filename, CP_ACP, False)
    End If
  End Function

Public Function URLEncode(ByVal xURL As String, Optional ByVal ExcludeChars As String) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  
  xLong1 = Len(xURL)
  If Not xLong1 = 0& Then
    xLong2 = WideCharToMultiByte(65001, 0&, ByVal StrPtr(xURL), xLong1, ByVal 0&, 0&, ByVal 0&, ByVal 0&)
    xChar1 = String(xLong2, vbNullChar)
    xLong1 = WideCharToMultiByte(65001, 0&, ByVal StrPtr(xURL), xLong1, ByVal xChar1, xLong2, ByVal 0&, ByVal 0&)
    If xLong1 = xLong2 Then
      For xLong1 = 1& To Len(xChar1)
        xLong2 = Asc(Mid(xChar1, xLong1, 1&)) 'ascW?
        If InStr(ExcludeChars, Chr(xLong2)) = 0& Then
          Select Case xLong2
            Case 45&, 46&, 48& To 57&, 65& To 90&, 95&, 97& To 122& ', 126&
              URLEncode = URLEncode + Chr(xLong2)
            Case Else
              URLEncode = URLEncode + "%" + Right("0" + Hex(xLong2), 2&)
            End Select
          Else
          URLEncode = URLEncode + Chr(xLong2)
          End If
        Next
      End If
    End If
  End Function

Public Function URLDecode(ByVal xURL As String) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xChar1 As String
  
  xLong2 = Len(xURL)
  If Not xLong2 = 0& Then
    Do
      xLong1 = xLong1 + 1&
      If Asc(Mid(xURL, xLong1, 1&)) = 37& And xLong1 < xLong2 - 1& Then
        xLong3 = Val("&h" + Mid(xURL, xLong1 + 1&, 2&) + "&")
        If xLong3 = 0& Then
          xChar1 = xChar1 + Mid(xURL, xLong1, 1&)
          Else
          xChar1 = xChar1 + Chr(xLong3)
          xLong1 = xLong1 + 2&
          End If
        Else
        xChar1 = xChar1 + Mid(xURL, xLong1, 1&)
        End If
      Loop While xLong1 < xLong2
    xLong1 = Len(xChar1)
    If Not xLong1 = 0& Then
      xLong2 = MultiByteToWideChar(65001, 0&, ByVal xChar1, xLong1, ByVal 0&, 0&)
      xURL = String(xLong2, vbNullChar)
      xLong1 = MultiByteToWideChar(65001, 0&, ByVal xChar1, xLong1, ByVal StrPtr(xURL), xLong2)
      If xLong1 = xLong2 Then
        URLDecode = xURL
        End If
      End If
    End If
  End Function

Public Function WinHelp(ByVal hWnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwdata As Variant) As Long
  Dim xChar1 As String
  Dim xChar2 As String
  Dim xLong1 As Long

  If IsUnicode Then
    xChar1 = String(258&, vbNullChar)
    xLong1 = GetShortPathNameW(StrPtr(lpHelpFile), StrPtr(xChar1), 257&)
    If (xLong1 < 257&) And Not xLong1 = 0& Then lpHelpFile = Left(xChar1, xLong1)
    If VarType(dwdata) = vbString Then
      xChar2 = dwdata
      WinHelp = WinHelpW(hWnd, StrPtr(lpHelpFile), wCommand, ByVal StrPtr(xChar2))
      Else
      xLong1 = dwdata
      WinHelp = WinHelpW(hWnd, StrPtr(lpHelpFile), wCommand, ByVal xLong1)
      End If
    Else
    If VarType(dwdata) = vbString Then
      xChar2 = dwdata
      WinHelp = WinHelpA(hWnd, lpHelpFile, wCommand, ByVal xChar2)
      Else
      xLong1 = dwdata
      WinHelp = WinHelpA(hWnd, lpHelpFile, wCommand, ByVal xLong1)
      End If
    End If
  End Function

Public Function HtmlHelp(ByVal hWnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwdata As Variant) As Long
  Dim xChar1 As String
  Dim xChar2 As String
  Dim xLong1 As Long
  
  If wCommand = &H12& Then
#If DoEventsEx_GetTickCount And DoEventsEx_GetElapsedTime Then
    If Not HtmlHelp_LastCall = 0& Then
      HtmlHelp_LastCall = 1000 - DoEventsEx_GetElapsedTime(HtmlHelp_LastCall)
      If HtmlHelp_LastCall > 0& And HtmlHelp_LastCall < 1000& Then
        Sleep HtmlHelp_LastCall
        End If
      HtmlHelp_LastCall = 0&
#Else
    If HtmlHelp_Active Then
      Sleep 333&
      HtmlHelp_Active = False
#End If
      On Error GoTo Er1
      If IsUnicode Then
        HtmlHelp = HtmlHelpW(0&, 0&, wCommand, ByVal 0&)
        Else
        HtmlHelp = HtmlHelpCloseA(0&, 0&, wCommand, ByVal 0&)
        End If
      On Error GoTo 0
      End If
    Else
    If IsUnicode Then
      xChar1 = String(258&, vbNullChar)
      xLong1 = GetShortPathNameW(StrPtr(lpHelpFile), StrPtr(xChar1), 257&)
      If (xLong1 < 257&) And Not xLong1 = 0& Then lpHelpFile = Left(xChar1, xLong1)
      If VarType(dwdata) = vbString Then
        xChar2 = dwdata
        On Error GoTo Er1
        HtmlHelp = HtmlHelpW(hWnd, StrPtr(lpHelpFile), wCommand, ByVal StrPtr(xChar2))
        Else
        xLong1 = dwdata
        On Error GoTo Er1
        HtmlHelp = HtmlHelpW(hWnd, StrPtr(lpHelpFile), wCommand, ByVal xLong1)
        End If
      On Error GoTo 0
      Else
      If VarType(dwdata) = vbString Then
        xChar2 = dwdata
        On Error GoTo Er1
        HtmlHelp = HtmlHelpA(hWnd, lpHelpFile, wCommand, ByVal xChar2)
        Else
        xLong1 = dwdata
        On Error GoTo Er1
        HtmlHelp = HtmlHelpA(hWnd, lpHelpFile, wCommand, ByVal xLong1)
        End If
      On Error GoTo 0
      End If
    #If DoEventsEx_GetTickCount And DoEventsEx_GetElapsedTime Then
      If Not HtmlHelp_LastCall = 0& Then
        HtmlHelp_LastCall = DoEventsEx_GetTickCount()
        End If
      #Else
      If HtmlHelp Then
        HtmlHelp_Active = True
        End If
      #End If
Rs1:
    End If
  Exit Function
  
Er1:
  Resume Rs1
  End Function

Public Function GetTimeFormatNow(Optional ByVal xMode As Long = 0&) As String
  Dim xLong1 As Long
  Dim xType1 As SYSTEMTIME
  
  Call GetSystemTime(xType1)
  If IsUnicode Then
    xLong1 = GetTimeFormatW(1024&, 0&, xType1, 0&, ptrTemp, ptrTempSizeXW)
    Else
    xLong1 = GetTimeFormatA(1024&, 0&, xType1, 0&, ptrTemp, ptrTempSizeX)
    End If
  If xLong1 > 0& Then GetTimeFormatNow = PeekS(ptrTemp, xLong1)
  End Function

Public Function DoEventsEx_IsTickCountElapsed(ByVal FirstTickCountValue As Long, ByVal TimeIntervalMs As Long) As Boolean
  Dim xLong1 As Long

  If FirstTickCountValue = 0 Then
    DoEventsEx_IsTickCountElapsed = True
    Else
    xLong1 = GetTickCount And &H3FFFFFFF
    If xLong1 < FirstTickCountValue Then
      DoEventsEx_IsTickCountElapsed = (xLong1 + &H40000000 > FirstTickCountValue + TimeIntervalMs)
      Else
      DoEventsEx_IsTickCountElapsed = (xLong1 > FirstTickCountValue + TimeIntervalMs)
      End If
    End If
  End Function

' Works with max &hfffffffff for Value/ToAdd (and output Value)
Public Sub UIntAddUInt(ByRef Value As Long, ByRef ToAdd As Long)
  Dim xLong1 As Long
  
  xLong1 = (((Value And &HFF000000) \ &H1000000) And &HFF&) + (((ToAdd And &HFF000000) \ &H1000000) And &HFF&) '<- seperate highest 8 bits (1byte)
  Value = (Value And &HFFFFFF) + (ToAdd And &HFFFFFF) '<- add
  xLong1 = xLong1 + Value \ &H1000000 '<- add overflows to seperated higher 8 bits (1byte)
  Value = ((xLong1 And &H7F&) * &H1000000 + (Value And &HFFFFFF)) Or (&H80000000 * (xLong1 \ &H80&))
  '        re-add all but highest bit     / Values (w/o bits just filtered)
  '                                                                   Re-Adding highest bit
  'UIntAddUInt = Value
  End Sub

Public Function Ellipsis_PathSmartStart(ByVal hdc As Long, ByVal xPath As String, ByVal MaxWidthPX As Long) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  Dim xChar2 As String
    
  If GetTextOutWidth(hdc, xPath) > MaxWidthPX Then
    If Left(xPath, 2) = "\\" Then xLong1 = 2&
    xLong1 = InStr(xLong1 + 1&, xPath, "\")
    If xLong1 = 0& Then
      xPath = "\" + xPath
      GoTo NoPathFix
      End If
    xChar1 = Left(xPath, xLong1)
    xPath = Mid(xPath, xLong1 + 1&)
      
    xLong1 = InStr(xPath, "\")
    If xLong1 = 0& Then
      xPath = "\" + xPath
      GoTo NoPathFix
      End If
    xChar2 = Left(xPath, xLong1 - 1&)
    xPath = Mid(xPath, xLong1)
    xLong2 = Len(xChar2) - 1&
    Do Until (xLong2 < 0&)
      Ellipsis_PathSmartStart = xChar1 + Left(xChar2, xLong2) + "..." + xPath
'Debug.Print "Test:", Ellipsis_PathSmartStart
      If GetTextOutWidth(hdc, Ellipsis_PathSmartStart) <= MaxWidthPX Then GoTo FoundIt
      xLong2 = xLong2 - 1&
      Loop
      
    xLong1 = InStrRev(xPath, "\")
    If xLong1 > 1& Then
      xChar2 = Left(xPath, xLong1 - 1&)
      xPath = Mid(xPath, xLong1)
      If GetTextOutWidth(hdc, xPath) < MaxWidthPX Then
        'else SkipSomePathing
ReLoopLAN:
        xLong2 = Len(xChar2) - 1&
        Do Until (xLong2 < 0&)
          Ellipsis_PathSmartStart = xChar1 + "..." + Right(xChar2, xLong2) + xPath
'Debug.Print "Test:", Ellipsis_PathSmartStart
          If GetTextOutWidth(hdc, Ellipsis_PathSmartStart) <= MaxWidthPX Then GoTo FoundIt
          xLong2 = xLong2 - 1&
          Loop

        If Left(xChar1, 2&) = "\\" And Len(xChar1) > 4& Then
          xChar1 = "\\"
          GoTo ReLoopLAN
          End If
        End If
NoPathFix:
      Ellipsis_PathSmartStart = Ellipsis_TextEnd(hdc, Mid(xPath, 2&), MaxWidthPX)
      End If
FoundIt:
    Else
    Ellipsis_PathSmartStart = xPath
    End If
  End Function

Public Sub HyperLinkList_InfoDialog(ByVal ResID As Long, ByVal InitCallback As Long, ByVal hWndParent As Long, Optional ByVal URLHandler As Long, Optional ByVal IconID As Long, Optional ByVal ListID As Long = 5&, Optional ByVal FocusID As Long = 9&)
  Dim xLong1 As Long
  Dim xType1 As HyperLinkList_InfoDialog_Data
  
  If Not InitCallback = 0& Then
    With xType1
      .IconID = IconID
      .CallBack = InitCallback
      .HListID = ListID
      '.FocusID = FocusID
      .CallURL = URLHandler
      End With
  
    xLong1 = LocalAlloc(0&, HyperLinkList_InfoDialog_DataLen)
    If Not xLong1 = 0& Then
      Call RtlMoveMemory(ByVal xLong1, xType1, HyperLinkList_InfoDialog_DataLen)
      #If InIDE Then
        #If LoadResEx_SetThemeFile Then
          Call DialogBoxIndirectParam(ResID, hWndParent, AddressOf HyperLinkList_InfoDialog_Proc, xLong1, LoadResEx_ThemeFile_hModule)
          #ElseIf LoadResEx_SetLanguageFile Then
          Call DialogBoxIndirectParam(ResID, hWndParent, AddressOf HyperLinkList_InfoDialog_Proc, xLong1, LoadResEx_LanguageFile_hModule)
          #Else
          Call DialogBoxIndirectParam(ResID, hWndParent, AddressOf HyperLinkList_InfoDialog_Proc, xLong1)
          #End If
        #Else
        Call DialogBoxIndirectParam(ResID, hWndParent, AddressOf HyperLinkList_InfoDialog_Proc, xLong1)
        #End If
      Call LocalFree(xLong1)
      End If
    End If
  End Sub

Private Function HyperLinkList_InfoDialog_Init(ByVal HWndDialog As Long, ByVal lParam As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As HyperLinkList_InfoDialog_Data
  
  If Not lParam = 0& Then
    Call RtlMoveMemory(xType1, ByVal lParam, HyperLinkList_InfoDialog_DataLen)
    xLong1 = GetDlgItem(HWndDialog, xType1.HListID)
    If Not xLong1 = 0& Then
      If Not xType1.IconID = 0& Then
        xType1.hIcon = LoadResEx_Icon(xType1.IconID)
        End If
      Call HookWindow(xLong1, AddressOf HyperlinkList_Proc)
      Call CallFunction_Fast(xType1.CallBack, xLong1, xType1.hIcon)
      End If
    'xLong1 = GetDlgItem(HWndDialog, xType1.FocusID)
    'If Not xLong1 = 0& Then
    '  Call SetFocusAPI(xLong1)
    '  Else
    '  HyperLinkList_InfoDialog_Init = 1&
    '  End If
    Call RtlMoveMemory(ByVal lParam, xType1, HyperLinkList_InfoDialog_DataLen)
    Call SetWindowLong(HWndDialog, -21&, lParam)
    End If
  End Function

Private Sub HyperLinkList_InfoDialog_Destroy(ByVal HWndDialog As Long)
  Dim xLong1 As Long
  Dim xType1 As HyperLinkList_InfoDialog_Data
  
  xLong1 = GetWindowLong(HWndDialog, -21&)
  If Not xLong1 = 0& Then
    Call RtlMoveMemory(xType1, ByVal xLong1, HyperLinkList_InfoDialog_DataLen)
    xLong1 = GetDlgItem(HWndDialog, xType1.HListID)
    If Not xLong1 = 0& Then
      Call UnhookWindow(xLong1)
      End If
    If Not xType1.hIcon = 0& Then
      Call DestroyIcon(xType1.hIcon)
      End If
    End If
  End Sub

Private Sub HyperLinkList_InfoDialog_OpenURL(ByVal HWndDialog As Long, ByVal hWnd As Long)
  Dim xLong1 As Long
  'Dim xChar1 As String
  Dim xType1 As HyperLinkList_InfoDialog_Data

  If Not hWnd = 0& Then
    xLong1 = GetWindowLong(HWndDialog, -21&)
    If Not xLong1 = 0& Then
      Call RtlMoveMemory(xType1, ByVal xLong1, HyperLinkList_InfoDialog_DataLen)
      If Not xType1.CallURL = 0& Then
        xLong1 = SendMessageA(hWnd, &H19F&, 0&, ByVal 0&)
        If xLong1 >= 0& Then
          xLong1 = HyperlinkList_GetURLPointerFromItem(hWnd, xLong1)
          If Not Len(xLong1) = 0& Then
            Call CallFunction_Fast(xType1.CallURL, HWndDialog, xLong1)
            'Call ShellExecute(HWndDialog, "Open", xChar1, "", "", 5&)
            'Clipboard.Clear
            'Clipboard.SetText xChar1, Text
            End If
          End If
        End If
      End If
    End If
  End Sub

Private Function HyperLinkList_InfoDialog_GetListDlgID(ByVal HWndDialog As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As HyperLinkList_InfoDialog_Data
  
  xLong1 = GetWindowLong(HWndDialog, -21&)
  If Not xLong1 = 0& Then
    Call RtlMoveMemory(xType1, ByVal xLong1, HyperLinkList_InfoDialog_DataLen)
    HyperLinkList_InfoDialog_GetListDlgID = xType1.HListID
    End If
  End Function

Private Function HyperLinkList_InfoDialog_Proc(ByVal HWndDialog As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case Msg
    Case &H2B& ' WM_DRAWITEM
      HyperLinkList_InfoDialog_Proc = HyperlinkList_WM_DRAWITEM(lParam)
      Exit Function
    Case &H110& 'WM_INITDIALOG
      HyperLinkList_InfoDialog_Proc = HyperLinkList_InfoDialog_Init(HWndDialog, lParam)
      Exit Function
    Case &H111& 'WM_COMMAND
      If lParam = 0& Then
        If wParam = 2& Then
          Call EndDialog(HWndDialog, 0&)
          End If
        ElseIf (GetWindowLong(lParam, -16&) And &HE&) = 0& Then
        If (wParam And &HFFFF&) = HyperLinkList_InfoDialog_GetListDlgID(HWndDialog) Then
          If (wParam And &HFFFF0000) = &H20000 Then
            Call HyperLinkList_InfoDialog_OpenURL(HWndDialog, lParam)
            End If
          Else
          Call EndDialog(HWndDialog, 0&)
          End If
        End If
    Case &H10& 'WM_CLOSE
      Call EndDialog(HWndDialog, 0&)
    Case &H2& 'WM_DESTROY
      HyperLinkList_InfoDialog_Destroy (HWndDialog)
    Case &H2C& ' WM_MEASUREITEM
      HyperLinkList_InfoDialog_Proc = HyperlinkList_WM_MEASUREITEM(lParam)
      Exit Function
    Case &H2D& ' WM_DELETEITEM
      HyperLinkList_InfoDialog_Proc = HyperlinkList_WM_DELETEITEM(lParam)
      Exit Function
    End Select
  'HyperLinkList_InfoDialog_Proc = HookedWindowProc(hwnd, Msg, wParam, lParam)
  End Function


Public Sub PokeL(ByVal ptrMem As Long, ByVal Value As Long)
  Call RtlMoveMemory(ByVal ptrMem, ByVal VarPtr(Value), 4&)
  End Sub

Private Function CallFunction_Real(ByVal FunctionAddress As Long) As Long
  Dim xLong1 As Long

  ReDim CallFunction_tmpArray(9& + 5& * (UBound(CallFunction_tmpParam())))  '5x due no cdll
  CallFunction_tmpPAPos = 0&
  For xLong1 = UBound(CallFunction_tmpParam()) - 1& To 0& Step -1&
    CallFunction_AddOpCode32 &H68&, CallFunction_tmpParam(xLong1)
    Next
  CallFunction_AddOpCode32 &HB8&, FunctionAddress 'mov eax, ...
  CallFunction_AddOpCode32 &HFF&, &H10C2D0        ' call eax, ret 10
  
  xLong1 = VirtualAlloc(0&, CallFunction_tmpPAPos + 15&, &H1000&, 4&)
  If Not xLong1 = 0& Then
    FunctionAddress = xLong1
    Call UIntAddUInt(FunctionAddress, 15&)
    FunctionAddress = (FunctionAddress And &HFFFFFFF0)
    Call RtlMoveMemory(ByVal FunctionAddress, CallFunction_tmpArray(0), CallFunction_tmpPAPos)
    If Not VirtualProtect(ByVal xLong1, CallFunction_tmpPAPos + 15&, &H20&, 0&) = 0& Then
      CallFunction_Real = CallWindowProcA(FunctionAddress, 0, 0, 0, 0)
      End If
    Call VirtualFree(xLong1, 0&, &H8000&)
    End If
  
  On Error Resume Next
  xLong1 = Timer
  On Error GoTo 0
  ReDim CallFunction_tmpParam(0&)
  ReDim CallFunction_tmpArray(0&)
  End Function

Private Sub CallFunction_AddOpCode32(ByVal preByte As Long, ByVal xLong1 As Long)
  CallFunction_tmpArray(CallFunction_tmpPAPos) = preByte
  Call RtlMoveMemory(CallFunction_tmpArray(CallFunction_tmpPAPos + 1&), ByVal VarPtr(xLong1), 4&)
  CallFunction_tmpPAPos = CallFunction_tmpPAPos + 5&
  End Sub

Private Sub OPENFILENAME_Patch(ByRef xType1 As OPENFILENAME, ByRef xType2 As OPENFILENAME_Real)
  Dim xChar1 As String
  Dim xLong1 As Long
  
  xChar1 = xType1.Filter
  If Not Right(xChar1, 1&) = vbNullChar Then
    xChar1 = xChar1 & vbNullChar & vbNullChar
    ElseIf Not Right(xChar1, 2&) = vbNullChar & vbNullChar Then
    xChar1 = xChar1 & vbNullChar
    End If
  xType2.lpstrFilter = LocalAllocFromString(xChar1)
  #If GetSaveFileName Then
    xType2.lCustData = Len(xChar1)
    #End If
  If Not Len(xType1.Title) = 0& Then
    xType2.lpstrTitle = LocalAllocFromString(xType1.Title)
    End If
  xType2.nFilterIndex = xType1.FilterIndex
  If xType2.nFilterIndex < 1& Then xType2.nFilterIndex = 1&
  xLong1 = (1& - CLng(IsUnicode)) * (OPENFILENAME_DataSize + 2&)
  xType2.lpstrFile = LocalAlloc(0&, xLong1)
  xType2.lpstrFileTitle = LocalAlloc(0&, xLong1)
  If Not xType2.lpstrFile = 0& Then
    xLong1 = 0&
    Call RtlMoveMemory(ByVal xType2.lpstrFile, ByVal VarPtr(xLong1), 2&)
    End If
  xType2.nMaxFile = OPENFILENAME_DataSize
  xType2.nMaxFileTitle = OPENFILENAME_DataSize
  xType2.lStructSize = 76&
  xType2.hWndOwner = xType1.hWndOwner
  xType2.hInstance = App.hInstance

  xChar1 = xType1.InitialDirFile
  If Not Len(xChar1) = 0& Then
    xLong1 = GetFileAttributes(xChar1)
    If Not (xLong1 = -1& Or (xLong1 And &H10&) = &H10&) Then
      xLong1 = InStrRev(xChar1, "\")
      If Not xLong1 = 0& Then
        #If GetSaveFileName Then
          xType2.Ext_SaveName = Mid(xChar1, xLong1 + 1&)
          #End If
        xChar1 = Left(xChar1, xLong1 - 1&)
        End If
      End If
    End If
  If Not Len(xChar1) = 0& Then
    xType2.lpstrInitialDir = LocalAllocFromString(xChar1)
    End If
  End Sub

Private Sub OPENFILENAME_Free(ByRef xType2 As OPENFILENAME_Real)
  With xType2
    If Not .lpstrFilter = 0& Then Call LocalFree(.lpstrFilter)
    If Not .lpstrTitle = 0& Then Call LocalFree(.lpstrTitle)
    If Not .lpstrFile = 0& Then Call LocalFree(.lpstrFile)
    If Not .lpstrFileTitle = 0& Then Call LocalFree(.lpstrFileTitle)
    If Not .lpstrInitialDir = 0& Then Call LocalFree(.lpstrInitialDir)
    End With
  End Sub

Public Function FormatMessage(ByVal dwFlags As Long, ByVal lpSource As Long, ByVal dwMessageId As Long) As String
  If IsUnicode Then
    dwFlags = FormatMessageW(dwFlags, ByVal lpSource, dwMessageId, 0&, ptrTemp, ptrTempSizeXW, 0&)
    Else
    dwFlags = FormatMessageA(dwFlags, ByVal lpSource, dwMessageId, 0&, ByVal ptrTemp, ptrTempSizeX, 0&)
    End If
  If Not dwFlags = 0& Then FormatMessage = PeekS(ptrTemp, dwFlags)
  End Function

Public Function LocalAllocFromString_Wide(ByVal xChar1 As String) As Long
  Dim xLong1 As Long
  
  xChar1 = xChar1 & vbNullChar
  xLong1 = Len(xChar1) * 2&
  LocalAllocFromString_Wide = LocalAlloc(0&, xLong1)
  If Not LocalAllocFromString_Wide = 0& Then
    Call RtlMoveMemory(ByVal LocalAllocFromString_Wide, ByVal StrPtr(xChar1), xLong1)
    End If
  End Function

Public Function LocalAllocFromString(ByVal xChar1 As String) As Long ', Optional ByVal FixedPos As Boolean = True) As Long
  Dim xLong1 As Long
  
  xChar1 = xChar1 & vbNullChar
  xLong1 = Len(xChar1) * (1& - CLng(IsUnicode))
  
  LocalAllocFromString = LocalAlloc(0&, xLong1)
  If Not LocalAllocFromString = 0& Then
    If IsUnicode Then
      Call RtlMoveMemory(ByVal LocalAllocFromString, ByVal StrPtr(xChar1), xLong1)
      Else
      Call RtlMoveMemory(ByVal LocalAllocFromString, ByVal xChar1, xLong1)
      End If
    End If
  End Function

Public Function GetClassName(ByVal hWnd As Long) As String
  If IsUnicode Then
    hWnd = GetClassNameW(hWnd, ptrTemp, ptrTempSizeXW)
    Else
    hWnd = GetClassNameA(hWnd, ptrTemp, ptrTempSizeX)
    End If
  GetClassName = PeekS(ptrTemp, hWnd)
  End Function

Public Sub DoEventsEx_Sleep(ByVal IntervalMS As Long)
  Dim xType1 As FILETIME
  Dim xLong1 As Long
  Dim xLong2 As Long

  If DoEventsEx_Sleep_WaitableTimers Then
    If IsUnicode Then
      xLong1 = CreateWaitableTimerW(0, True, 0&)
      Else
      xLong1 = CreateWaitableTimerA(0, True, 0&)
      End If
    If xLong1 = 0& Then GoTo CustomTimerW9x
    xType1.dwLowDateTime = -1&
    xType1.dwHighDateTime = -1&
    Call SetWaitableTimer(xLong1, xType1, 0&, 0&, 0&, 0&)
    xType1.dwLowDateTime = IntervalMS * -10000&
    Call SetWaitableTimer(xLong1, xType1, 0&, 0&, 0&, False)
    Do Until MsgWaitForMultipleObjects(1&, xLong1, False, -1&, 255&) = 0&
      DoEvents
      Loop
    DoEvents
    Call CloseHandle(xLong1)
    Else
CustomTimerW9x:
    xLong1 = GetTickCount And &H3FFFFFFF
    Do
      DoEvents
      Sleep SleepValueLow
      DoEvents
      xLong2 = GetTickCount And &H3FFFFFFF
      If xLong2 < xLong1 Then
        If xLong2 + &H40000000 - xLong1 > IntervalMS Then Exit Do
        Else
        If (xLong2 - xLong1) > IntervalMS Then Exit Do
        End If
      Loop
    DoEvents
    End If
  End Sub

Public Function CreateWindowEx(ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, Optional ByVal hMenu As Long, Optional ByVal lpParam As Long) As Long
  If IsUnicode Then
    CreateWindowEx = CreateWindowExW(dwExStyle, StrPtr(lpClassName), StrPtr(lpWindowName), dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, App.hInstance, lpParam)
    Else
    CreateWindowEx = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, App.hInstance, lpParam)
    End If
  End Function

Public Sub GetOptMonitorFromPoint(ByVal x As Long, ByVal y As Long, ByRef RectMonitor As RECT)
  Dim xLong1 As Long
  Dim xType2 As MONITORINFO
  
  Call SystemParametersInfoA(48&, 0&, RectMonitor, 0&)
  On Error GoTo NoMMApiEr
  xLong1 = MonitorFromPoint(x, y, &H2&)
  On Error GoTo 0
  If Not xLong1 = 0& Then
    xType2.cbSize = Len(xType2)
    If Not GetMonitorInfoA(xLong1, xType2) = 0& Then
      Call RtlMoveMemory(RectMonitor, xType2.rcWork, 16&)
      End If
    End If
  
NoMMApiRs:
  On Error GoTo 0
  Exit Sub
  
NoMMApiEr:
  Resume NoMMApiRs
  End Sub

Public Function PostMessage(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  If IsUnicode Then
    PostMessage = PostMessageW(hWnd, wMsg, wParam, ByVal lParam)
    Else
    PostMessage = PostMessageA(hWnd, wMsg, wParam, ByVal lParam)
    End If
  End Function

Public Function SendMessage(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  If IsUnicode Then
    SendMessage = SendMessageW(hWnd, Msg, wParam, ByVal lParam)
    Else
    SendMessage = SendMessageA(hWnd, Msg, wParam, ByVal lParam)
    End If
  End Function

Public Sub WindowToCursorPos(ByRef xWindowSize As POINTAPI, ByRef xType1 As POINTAPI)
  Dim xLong1 As Long
  Dim xCursorPlusX As Long
  Dim xCursorPlusX2 As Long
  Dim xCursorPlusY As Long
  Dim xCursorPlusY2 As Long
  Dim xType2 As RECT
  #If GetOptCursorHotSpotOffset Then
    #Else
    Dim xType3 As ICONINFO
    #End If
  
  Call GetCursorPos(xType1)
  Call GetOptMonitorFromPoint(xType1.x, xType1.y, xType2)

  #If GetOptCursorHotSpotOffset Then
    Call GetOptCursorHotSpotOffset(xCursorPlusX, xCursorPlusY, xCursorPlusX2, xCursorPlusY2)
    #Else
    xLong1 = LoadCursor(&H7F00&)
    Call GetIconInfo(xLong1, xType3)
    If Not xType3.hbmMask = 0& Then Call DeleteObject(xType3.hbmMask)
    If Not xType3.hbmColor = 0& Then Call DeleteObject(xType3.hbmColor)
    If xType3.xHotspot > 16& Then
      xCursorPlusX = 36& - xType3.xHotspot
      xCursorPlusX2 = 16&
      Else
      xCursorPlusX = 16&
      xCursorPlusX2 = 4& + xType3.xHotspot
      End If
    If xType3.yHotspot > 16& Then
      xCursorPlusY = 36& - xType3.yHotspot
      xCursorPlusY2 = 16&
      Else
      xCursorPlusY = 16&
      xCursorPlusY2 = 4& + xType3.yHotspot
      End If
    #End If
    
  If xType1.x + xWindowSize.x + xCursorPlusX > xType2.Right Then
    xType1.x = xType1.x - xWindowSize.x - xCursorPlusX2
    'If xType1.x + xWindowSize.x + xCursorPlusX > xType2.Right Then
    If xType1.x + xWindowSize.x > xType2.Right Then
      xType1.x = xType2.Right - xWindowSize.x
      End If
    Else
    xType1.x = xType1.x + xCursorPlusX
    End If
    
  If xType1.y + xWindowSize.y + xCursorPlusY > xType2.Bottom Then
    xType1.y = xType1.y - xWindowSize.y - xCursorPlusY2
    If xType1.y + xWindowSize.y + xCursorPlusY > xType2.Bottom Then
      xType1.y = xType2.Bottom - xWindowSize.y
      End If
    Else
    xType1.y = xType1.y + xCursorPlusY
    End If
  If xType1.x < xType2.Left Then xType1.x = xType2.Left
  If xType1.y < xType2.Top Then xType1.y = xType2.Top
  'Debug.Print xType1.x, xType1.y
  End Sub

Public Function DialogBoxIndirectParam(ByVal ResDialogOrID As Variant, ByVal hWndParent As Long, ByVal lpDialogFunc As Long, ByVal xParam As Long, Optional ByVal hModule As Long) As Long
  Dim xChar1 As String
  
  #If LoadResEx_SetLanguageFile Then
    xChar1 = LoadResEx_Data(ResDialogOrID, 5, LoadResEx_LanguageFile_hModule)
    #Else
    xChar1 = LoadResEx_Data(ResDialogOrID, 5, App.hInstance)
    #End If
  If Not Len(xChar1) = 0& Then
    If hModule = 0& Then
      #If InIDE And Not CustomClassesInDialogs And LoadResEx_SetThemeFile Then
        hModule = LoadResEx_ThemeFile_hModule
        If hModule = 0& Then hModule = App.hInstance
        #ElseIf InIDE And Not CustomClassesInDialogs And LoadResEx_SetLanguageFile Then
        hModule = LoadResEx_LanguageFile_hModule
        If hModule = 0& Then hModule = App.hInstance
        #Else
        hModule = App.hInstance
        #End If
      End If
    If IsUnicode Then
      DialogBoxIndirectParam = DialogBoxIndirectParamW(hModule, xChar1, hWndParent, lpDialogFunc, xParam)
      Else
      DialogBoxIndirectParam = DialogBoxIndirectParamA(hModule, xChar1, hWndParent, lpDialogFunc, xParam)
      End If
    End If
  End Function

Private Function IconIDIsUseable(ByVal xCurIndex As Long, ByVal xOrigIndex As Long) As Boolean
  IconIDIsUseable = (IconIDIs16bit(xCurIndex) Or Not IconIDIs16bit(xOrigIndex))
  End Function

Private Function IconIDIs16bit(ByVal xIndex As Long) As Boolean
  Select Case xIndex
    Case LoadResEx_IconOS_Win95_16Color, LoadResEx_IconOS_Win2000ME_16Color ', LoadResEx_IconOS_WinVista_16Color
      IconIDIs16bit = True
    End Select
  End Function

Public Function LoadResEx_StringEx(ByVal hModule As Long, ByVal ResID As Long) As String
  Dim xLong1 As Long

  If IsUnicode Then
    xLong1 = LoadStringW(hModule, ResID, ptrTemp, ptrTempSizeXW)
    Else
    xLong1 = LoadStringA(hModule, ResID, ptrTemp, ptrTempSizeX)
    End If
  If Not xLong1 = 0& Then
    LoadResEx_StringEx = PeekS(ptrTemp, xLong1)
    End If
  End Function

Public Function RemovableDevices_Register(ByVal hWnd As Long, ByVal DriveLetterID As Long) As Boolean
  Dim NotificationFilter As DEV_BROADCAST_HANDLE

#If Unicode Then
  If IsUnicode Then
#End If
    NotificationFilter.dbch_handle = CreateFileA(Chr(DriveLetterID + 65&) + ":\\", &H80000000, 3&, 0&, 3&, &H2000080, 0&)
    If Not NotificationFilter.dbch_handle = -1& Then
      NotificationFilter.dbcc_size = Len(NotificationFilter)
      NotificationFilter.dbcc_devicetype = 6&
      On Error GoTo Er1
      RemovableDevices_Handle(DriveLetterID) = RegisterDeviceNotificationA(hWnd, NotificationFilter, 0&)
Rs1:
      On Error GoTo 0
      Call CloseHandle(NotificationFilter.dbch_handle)
      RemovableDevices_Register = (Not (RemovableDevices_Handle(DriveLetterID) = 0&))
      End If
#If Unicode Then
    End If
#End If
  Exit Function

Er1:
  Resume Rs1
  End Function

Public Sub RemovableDevices_Unregister(ByVal DriveLetterID As Long)
  If Not RemovableDevices_Handle(DriveLetterID) = 0& Then
    Call UnregisterDeviceNotification(RemovableDevices_Handle(DriveLetterID))
    RemovableDevices_Handle(DriveLetterID) = 0&
    End If
  End Sub

Public Sub AquirePrivilege(ByVal PrivilegeName As String)
  Dim xLong1 As Long
  Dim xType1 As Single_TOKEN_PRIVILEGE

#If Unicode Then
  If IsUnicode Then
#Else
  If (GetVersion And &H80000000) = 0& Then
#End If
    If OpenProcessToken(GetCurrentProcess(), 40&, xLong1) Then
      If LookupPrivilegeValueA(ByVal 0&, PrivilegeName, xType1.pLuid) Then
        xType1.PrivilegeCount = 1&
        xType1.Attributes = 2&
        Call AdjustTokenPrivileges(xLong1, 0&, xType1, 0&, ByVal 0&, 0&)
        End If
      Call CloseHandle(xLong1)
      End If
    End If
  End Sub

Public Function CreateCodeFromHexAssembly(ByRef ptrExec As Long, ByRef ptrMem As Long, ByRef ByteCode As String) As Boolean
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xByteA1() As Byte
  
  xLong1 = Len(ByteCode)
  ReDim xByteA1(xLong1 - 1&)
  Call RtlMoveMemory(xByteA1(0), ByVal ByteCode, xLong1)
  xLong1 = xLong1 \ 2&
  ptrMem = VirtualAlloc(0&, xLong1 + 15&, &H1000&, 4&)
  If Not ptrMem = 0& Then
    ptrExec = ptrMem
    Call UIntAddUInt(ptrExec, 15&)
    ptrExec = (ptrExec And &HFFFFFFF0)
    For xLong2 = 0& To xLong1 - 1&
      xByteA1(xLong2) = CreateCodeFromHexAssembly_UnHexByte(xByteA1(xLong2 * 2&)) * 16& + CreateCodeFromHexAssembly_UnHexByte(xByteA1(xLong2 * 2& + 1&))
      Next
    Call RtlMoveMemory(ByVal ptrExec, xByteA1(0), xLong1)
    If VirtualProtect(ByVal ptrMem, xLong1 + 15&, &H20&, 0&) = 0& Then
      Call VirtualFree(ptrMem, 0&, &H8000&)
      Else
      CreateCodeFromHexAssembly = True
      End If
    End If
  End Function

Private Function CreateCodeFromHexAssembly_UnHexByte(ByVal xByte1 As Byte) As Byte
  Select Case CLng(xByte1)
    Case &H30& To &H39&
      CreateCodeFromHexAssembly_UnHexByte = xByte1 - &H30&
    Case &H41& To &H46&
      CreateCodeFromHexAssembly_UnHexByte = xByte1 - &H37&
    Case &H61 To &H66&
      CreateCodeFromHexAssembly_UnHexByte = xByte1 - &H57&
    Case Else
#If InIDE Then
#End If
      Stop
    End Select
  End Function

' Works with max &hfffffffff for Value/ToSub (and output Value)
Public Sub UIntSubUInt(ByRef Value As Long, ByRef ToSub As Long)
  Dim xLong1 As Long
  
  xLong1 = (((Value And &HFF000000) \ &H1000000) And &HFF&) - (((ToSub And &HFF000000) \ &H1000000) And &HFF&) '<- seperate highest 8 bits (1byte)
  Value = (Value And &HFFFFFF) - (ToSub And &HFFFFFF) '<- sub
  xLong1 = xLong1 + (Value And &HFF000000) \ &H1000000 '<- add overflows to seperated higher 8 bits (1byte)
  Value = ((xLong1 And &H7F&) * &H1000000 + (Value And &HFFFFFF)) Or (&H80000000 * ((xLong1 And &H80&) \ &H80&))
  '        re-add all but highest bit     / Values (w/o bits just filtered)
  '                                                                   Re-Adding highest bit
  'UIntSubUInt = Value
  End Sub

Public Function TxtFile_ReadOpen(ByVal Filename As String, Optional ByVal DefaultEncoding As TxtFile_EncodingEnum = CP_ACP) As Long
  Dim hFile As Long
  Dim xSize As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim hMemTmp As Long
  Dim xType1 As TxtFileReadStruct

  hFile = TxtFile_ReadOpenEx(Filename, DefaultEncoding, xSize, False)
  If Not hFile = -1& Then
    If xSize = 0& Then
      TxtFile_ReadOpen = LocalAlloc(&H40&, TxtFileReadStructLen)
      ElseIf DefaultEncoding = TxtFile_EncodingEnum.CP_WINUNICODE Then
      xType1.hMem = LocalAlloc(0&, xSize + 6&)
      If Not xType1.hMem = 0& Then
        If Not ReadFile(hFile, ByVal xType1.hMem, xSize, xLong1, 0&) = 0& Then
          If xSize = xLong1 Then GoTo Success1
          End If
        End If
      Else
      hMemTmp = LocalAlloc(0&, xSize + 1&)
      If Not hMemTmp = 0& Then
        If Not ReadFile(hFile, ByVal hMemTmp, xSize, xLong1, 0&) = 0& Then
          If xSize = xLong1 Then
            xLong1 = MultiByteToWideChar(DefaultEncoding, 0&, ByVal hMemTmp, xSize, 0&, 0&)
            If Not xLong1 = 0& Then
              xType1.hMem = LocalAlloc(0&, xLong1 * 2& + 8&)
              If Not xType1.hMem = 0& Then
                xLong2 = MultiByteToWideChar(DefaultEncoding, 0&, ByVal hMemTmp, xSize, ByVal xType1.hMem, xLong1)
                If xLong1 = xLong2 Then
                  xSize = xLong1 * 2
Success1:
                  xType1.Encoding = DefaultEncoding
                  TxtFile_ReadOpen = LocalAlloc(0&, TxtFileReadStructLen)
                  If Not TxtFile_ReadOpen = 0& Then
                    xType1.hMemPos = xType1.hMem
                    UIntAddUInt xSize, xType1.hMem
                    #If TxtFile_SetEncoding Or TxtFile_ReadLine Then
                      xType1.hMemEnd = xSize
                      #End If
                    Call RtlMoveMemory(ByVal TxtFile_ReadOpen, xType1, TxtFileReadStructLen)
                    Call RtlMoveMemory(ByVal xSize, ByVal StrPtr(vbCrLf), 4&)
                    UIntAddUInt xLong1, 4&
                    Call RtlMoveMemory(ByVal xSize, ByVal StrPtr(vbNullChar), 2&)
                    GoTo Success2
                    End If
                  End If
                Call LocalFree(xType1.hMem)
                End If
              End If
            End If
          End If
Success2:
        If Not hMemTmp = 0& Then
          Call LocalFree(hMemTmp)
          End If
        End If
      End If
    Call CloseHandle(hFile)
    End If
  End Function

Public Sub TxtFile_ReadClose(ByRef hTxtFileIn As Long)
  Dim xType1 As TxtFileReadStruct

  If Not hTxtFileIn = 0& Then
    Call RtlMoveMemory(xType1, ByVal hTxtFileIn, TxtFileReadStructLen)
    If Not xType1.hMem = 0& Then
      Call LocalFree(xType1.hMem)
      End If
    Call LocalFree(hTxtFileIn)
    hTxtFileIn = 0&
    End If
  End Sub

Public Function CreateFile(ByVal Filename As String, ByVal xOpenMode As eCreateFileOpenMode, ByVal xAccessMode As eCreateFileAccessMode) As Long
  If IsUnicode Then
    CreateFile = CreateFileW(ByVal StrPtr(Filename), xAccessMode, &H1&, 0&, xOpenMode, &H20&, 0&)
    Else
    CreateFile = CreateFileA(Filename, xAccessMode, &H1&, 0&, xOpenMode, &H20&, 0&)
    End If
  End Function


Private Function TxtFile_WriteString(ByVal hTxtFileOut As Long, ByVal xString As String) As Boolean
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
  Dim xType1 As TxtFileWriteStruct

  If Not hTxtFileOut = 0& Then
    Call RtlMoveMemory(xType1, ByVal hTxtFileOut, TxtFileWriteStructLen)
    If Not hTxtFileOut = -1& Then
      xLong1 = Len(xString)
      If xType1.Encoding = TxtFile_EncodingEnum.CP_WINUNICODE Then
        ' CP_WINUNICODE
        xLong1 = xLong1 * 2&
        xLong3 = WriteFile(xType1.hFile, ByVal StrPtr(xString), xLong1, xLong2, 0&)
        ElseIf xType1.Encoding = TxtFile_EncodingEnum.CP_UTF8 Then
        xLong2 = WideCharToMultiByte(xType1.Encoding, 0&, ByVal StrPtr(xString), xLong1, ByVal 0&, 0&, ByVal 0&, ByVal 0&)
        If Not xLong2 = 0& Then
          xLong4 = LocalAlloc(0&, xLong2 + 1&)
          If Not xLong4 = 0& Then
            xLong1 = WideCharToMultiByte(xType1.Encoding, 0&, ByVal StrPtr(xString), xLong1, ByVal xLong4, xLong2 + 1&, ByVal 0&, ByVal 0&)
            If xLong1 = xLong2 Then
              xLong3 = WriteFile(xType1.hFile, ByVal xLong4, xLong1, xLong2, 0&)
              Call LocalFree(xLong4)
              GoTo Check
              End If
            Call LocalFree(xLong4)
            End If
          End If
        GoTo Fail
        Else
        xLong3 = WriteFile(xType1.hFile, ByVal xString, xLong1, xLong2, 0&)
        End If
Check:
      If xLong1 = xLong2 And Not xLong3 = 0& Then
        TxtFile_WriteString = True
        Else
Fail:
        Call SetEndOfFile(xType1.hFile)
        Call CloseHandle(xType1.hFile)
        xType1.hFile = -1&
        Call RtlMoveMemory(ByVal hTxtFileOut, xType1, TxtFileWriteStructLen)
        End If
      End If
    End If
  End Function

Public Function TxtFile_WriteAppendEx(ByVal Filename As String, ByVal DefaultEncoding As TxtFile_EncodingEnum, ByVal DefaultByteOrderMark As Boolean) As Long
  Dim xType1 As TxtFileWriteStruct
  
  xType1.hFile = TxtFile_ReadOpenEx(Filename, xType1.Encoding, 0&, True)
  If xType1.hFile = -1& Then
    If GetFileAttributes(Filename) = -1& Then
      TxtFile_WriteAppendEx = TxtFile_WriteCreateEx(Filename, DefaultEncoding, DefaultByteOrderMark)
      End If
    Else
    TxtFile_WriteAppendEx = LocalAlloc(0&, TxtFileWriteStructLen)
    If Not TxtFile_WriteAppendEx = 0& Then
      Call RtlMoveMemory(ByVal TxtFile_WriteAppendEx, xType1, TxtFileWriteStructLen)
      GoTo Success
      End If
    Call CloseHandle(xType1.hFile)
    End If
Success:
  End Function

Public Function Ellipsis_TextEnd(ByVal hdc As Long, ByVal xText As String, ByVal MaxWidthPX As Long) As String
  Dim xLong1 As Long

  If GetTextOutWidth(hdc, xText) <= MaxWidthPX Then
    Ellipsis_TextEnd = xText
    Else
    xLong1 = Len(xText) - 1&
    Do Until (xLong1 < 0&)
      Ellipsis_TextEnd = Left(xText, xLong1) + "..."
      If GetTextOutWidth(hdc, Ellipsis_TextEnd) <= MaxWidthPX Then Exit Do
      xLong1 = xLong1 - 1&
      Loop
    End If
  End Function

Private Function HyperlinkList_HitTest(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType1 As RECT
  Dim xType2 As HyperlinkListItemStruct
        
  xLong1 = SendMessageA(hWnd, &H1A9&, 0&, ByVal lParam)
  If (xLong1 And &HFFFF0000) = 0& Then
    xLong2 = SendMessageA(hWnd, &H199&, xLong1, ByVal 0&)
    If Not xLong2 = 0& Then
      Call RtlMoveMemory(xType2, ByVal xLong2, HyperlinkListItemLen)
      If Not xType2.LnkURL = 0& Then
        If Not SendMessageA(hWnd, &H198&, xLong1, xType1) = -1& Then
          xLong1 = (lParam And &HFFFF&) - 1& ' x
          xLong2 = ((lParam And &HFFFF0000) \ &H10000) + 1& 'y
          If xLong1 > xType1.Left + xType2.LnkRect.Left + xType2.Padding.Left And xLong1 <= xType1.Left + xType2.LnkRect.Right + xType2.Padding.Left And xLong2 > xType1.Top + xType2.LnkRect.Top + xType2.Padding.Top And xLong2 <= xType1.Top + xType2.LnkRect.Bottom + xType2.Padding.Top Then
            HyperlinkList_HitTest = True
            End If
          End If
        End If
      End If
    End If
  End Function

Private Function HyperlinkList_WM_ERASEBKGND(ByVal hWnd As Long, ByVal wParam As Long) As Long
  Dim xType1 As RECT

  If Not wParam = 0& Then
    Call GetClientRect(hWnd, xType1)
    Call FillRect(wParam, xType1, 6&) '6&)
    End If
  End Function

Public Function HyperlinkList_Proc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case Msg
    Case &H100&, &H101& ' WM_Key
    Case &H104&, &H105& ' WM_SKey
    Case &H102& 'WM_CHAR
      If wParam = 32& Then
        Call SendMessageA(GetParent(hWnd), &H111&, GetDlgCtrlID(hWnd) Or &H20000, ByVal hWnd)
        End If
      Exit Function
    Case &H14&
      HyperlinkList_Proc = HyperlinkList_WM_ERASEBKGND(hWnd, wParam)
      Exit Function
    Case &H200&, &H202&
      Exit Function
    Case &H201&
      If HyperlinkList_HitTest(hWnd, lParam) Then
        HyperlinkList_Proc = HookedWindowProc(hWnd, Msg, 0&, lParam)
        Call HookedWindowProc(hWnd, &H202&, 0&, lParam)
        Else
        Call SetFocusAPI(hWnd)
        End If
      Exit Function
    Case &H203&
      If HyperlinkList_HitTest(hWnd, lParam) Then
        HyperlinkList_Proc = HookedWindowProc(hWnd, Msg, 0&, lParam)
        Call HookedWindowProc(hWnd, &H200&, 0&, lParam)
        'Call HookedWindowProc(hwnd, &H203&, 0&, lParam)
        Else
        Call SetFocusAPI(hWnd)
        End If
      Exit Function
    End Select
  HyperlinkList_Proc = HookedWindowProc(hWnd, Msg, wParam, lParam)
  End Function

Public Sub HyperlinkList_AddItem(ByVal hWnd As Long, ByVal xText As String, ByRef Padding As RECT, Optional ByVal hIcon As Long, Optional ByVal IconSizeXY As Long)
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
  Dim xLong5 As Long
  Dim xType1 As RECT
  Dim hdc As Long
  Dim hFont As Long
  Dim hFontOld As Long
  Dim xChar1 As String
  Dim xChar2 As String
  Dim xType2 As RECT

  Call GetClientRect(hWnd, xType1)
  If (GetWindowLongA(hWnd, -16&) And &H200000) = &H0& Then
    xType1.Right = xType1.Right - GetSystemMetrics(2&)
    End If

  hdc = CreateCompatibleDC(0&)
  If Not hdc = 0& Then
    hFont = SendMessageA(hWnd, &H31&, 0&, ByVal 0&)
    If Not hFont = 0& Then
      hFontOld = SelectObject(hdc, hFont)
      End If
    If hFont = 0& Or Not hFontOld = 0& Then
      xType2 = Padding
      #If HyperlinkList_UseIcons Then
        If IconSizeXY = 0& Then
          xText = WordWrapText(hdc, xText, xType1.Right - xType1.Left - Padding.Left - Padding.Right)
          Else
          xText = WordWrapText(hdc, xText, xType1.Right - xType1.Left - HyperlinkList_PaddingIcon - Padding.Left - Padding.Right - IconSizeXY)
          End If
        #Else
        xText = WordWrapText(hdc, xText, xType1.Right - xType1.Left - Padding.Left - Padding.Right)
        #End If

      xLong1 = InStr(xText, "://")
      xLong2 = InStr(xText, "@")
      If xLong2 < xLong1 And Not xLong2 = 0& Then xLong1 = xLong2
      If xLong1 = 0& Then
        #If HyperlinkList_UseIcons Then
          Call HyperlinkList_AddItemReal(hWnd, xText, DrawTextGetHeight(hdc, xText, &H510&), xType1, xType2, , , hIcon, IconSizeXY)
          #Else
          Call HyperlinkList_AddItemReal(hWnd, xText, DrawTextGetHeight(hdc, xText, &H510&), xType1, xType2)
          #End If
        Else
        xType2.Bottom = 0&
HLLoop:
        xLong2 = InStr(xLong1 + 3&, xText, "://")
        xLong5 = InStr(xLong1 + 3&, xText, "@")
        If xLong5 < xLong2 And Not xLong5 = 0& Then xLong2 = xLong5
        If Not xLong2 = 0& Then
          xLong2 = InStrRev(xText, vbCrLf, xLong2)
          End If
        If xLong2 = 0& Then
          xChar1 = xText
          xText = ""
          Else
          xChar1 = Left(xText, xLong2 - 1&)
          xText = Mid(xText, xLong2 + 2&)
          End If
    
    
        xLong2 = InStrRev(xChar1, " ", xLong1)
' <-- other begin signs ---
        xLong5 = InStrRev(xChar1, "(", xLong1)
        'If xLong5 > xLong2 And Not xLong5 = 0& Then xLong2 = xLong5
        If xLong5 > xLong2 Then xLong2 = xLong5
' --- other begin signs -->
        xLong3 = InStrRev(xChar1, vbCrLf, xLong1)
        If Not xLong3 = 0& Then xLong3 = xLong3 + 1&
        'If xLong3 > xLong2 And Not xLong3 = 0& Then xLong2 = xLong3
        If xLong3 > xLong2 Then xLong2 = xLong3
        xLong4 = InStr(xLong1, xChar1, " ")
' <-- other end signs ---
        xLong5 = InStr(xLong1, xChar1, ")")
        If xLong5 < xLong4 And Not xLong5 = 0& Then xLong4 = xLong5
' --- other end signs -->
        xLong5 = InStr(xLong1, xChar1, vbCrLf)
        If xLong5 = 0& Then xLong5 = Len(xChar1) + 1&
        If (xLong5 < xLong4 Or xLong4 = 0&) Then xLong4 = xLong5
        
        xChar2 = Left(xChar1, xLong4 - 1&)
'        Stop
        xType1.Bottom = DrawTextGetHeight(hdc, xChar2, &H510&)   ' total height
        xChar2 = Mid(xChar1, xLong3 + 1, xLong4 - xLong3 - 1)
        xType1.Right = DrawTextGetWidth(hdc, xChar2, &H510&) + 1& ' effective line total width
        xChar2 = Mid(xChar1, xLong2 + 1&, xLong4 - xLong2 - 1&)
          
        xType1.Top = xType1.Bottom - DrawTextGetHeight(hdc, xChar2, &H510&)
        xType1.Left = xType1.Right - DrawTextGetWidth(hdc, xChar2, &H510&) - 1&
          
    
        If Len(xText) = 0& Then
          xType2.Bottom = Padding.Bottom
          End If
        #If HyperlinkList_UseIcons Then
          Call HyperlinkList_AddItemReal(hWnd, xChar1, DrawTextGetHeight(hdc, xChar1, &H510&), xType1, xType2, xChar2, xChar2, hIcon, IconSizeXY)
          hIcon = 0&
          #Else
          Call HyperlinkList_AddItemReal(hWnd, xChar1, DrawTextGetHeight(hdc, xChar1, &H510&), xType1, xType2, xChar2, xChar2)
          #End If
        If Not Len(xText) = 0& Then
          xLong1 = InStr(xText, "://")
          xLong2 = InStr(xText, "@")
          If xLong2 < xLong1 And Not xLong2 = 0& Then xLong1 = xLong2
          xType2.Top = 0&
          GoTo HLLoop
          End If
        End If
      If Not hFont = 0& Then
        Call SelectObject(hdc, hFontOld)
        End If
      End If
    Call DeleteDC(hdc)
    End If
  End Sub

Public Sub HyperlinkList_AddItemReal(ByVal hWnd As Long, ByVal xText As String, ByVal xHeight As Long, ByRef LnkRect As RECT, ByRef Padding As RECT, Optional ByVal LnkURL As String, Optional ByVal LnkCaption As String, Optional ByVal hIcon As Long, Optional ByVal IconSizeXY As Long)
  Dim xLong1 As Long
  Dim xType1 As HyperlinkListItemStruct

  With xType1
    .LenText = Len(xText)
    If Not .LenText = 0& Then
      .xText = LocalAllocFromString(xText)
      End If
    If Not (Len(LnkURL) + Len(LnkCaption)) = 0& Then
      If Len(LnkCaption) = 0& Then
        LnkCaption = LnkURL
        ElseIf Len(LnkURL) = 0& Then
        LnkURL = LnkCaption
        End If
      .LnkRect = LnkRect
      .LnkURL = LocalAllocFromString(LnkURL)
      .LnkCapLen = Len(LnkCaption)
      .LnkCaption = LocalAllocFromString(LnkCaption)
      End If
    .Padding = Padding
    #If HyperlinkList_UseIcons Then
      If Not IconSizeXY = 0& Then
        If Not hIcon = 0& Then
          .hIcon = hIcon
          If IconSizeXY > xHeight Then
            xHeight = IconSizeXY
            End If
          .IconIdent = Padding.Left
          .IconSize = IconSizeXY
          End If
        .Padding.Left = Padding.Left + HyperlinkList_PaddingIcon + IconSizeXY
        End If
      #End If
    'If SendMessageA(hWnd, &H18B&, 0&, ByVal 0&) = 0& Then
      'xHeight = xHeight + HyperlinkList_PaddingT
      '.LnkRect.Top = .LnkRect.Top + HyperlinkList_PaddingT
      '.LnkRect.Bottom = .LnkRect.Bottom + HyperlinkList_PaddingT
      'End If
    .xHeight = xHeight + .Padding.Top + Padding.Bottom
    End With
  xLong1 = LocalAlloc(0&, HyperlinkListItemLen)
  If Not xLong1 = 0& Then
    Call RtlMoveMemory(ByVal xLong1, xType1, HyperlinkListItemLen)
    If Not SendMessageA(hWnd, &H180&, 0&, ByVal xLong1) < 0& Then
      GoTo Success
      End If
    Call LocalFree(xLong1)
    End If
  If Not xType1.xText = 0& Then Call LocalFree(xType1.xText)
  If Not xType1.LnkURL = 0& Then Call LocalFree(xType1.LnkURL)
  If Not xType1.LnkCaption = 0& Then Call LocalFree(xType1.LnkCaption)
Success:
  End Sub

Public Function HyperlinkList_WM_DELETEITEM(ByVal lParam As Long) As Long
  Dim xType1 As DELETEITEMSTRUCT
  Dim xType2 As HyperlinkListItemStruct
  
  If Not lParam = 0& Then
    Call RtlMoveMemory(xType1, ByVal lParam, 20&)
    If Not xType1.itemData = 0& Then
      Call RtlMoveMemory(xType2, ByVal xType1.itemData, HyperlinkListItemLen)
      If Not xType2.xText = 0& Then Call LocalFree(xType2.xText)
      If Not xType2.LnkURL = 0& Then Call LocalFree(xType2.LnkURL)
      If Not xType2.LnkCaption = 0& Then Call LocalFree(xType2.LnkCaption)
      'Stop
      Call LocalFree(xType1.itemData)
      End If
    End If
  HyperlinkList_WM_DELETEITEM = 1&
  End Function

Public Function HyperlinkList_WM_MEASUREITEM(ByVal lParam As Long) As Long
  Dim xType1 As MEASUREITEMSTRUCT
  Dim xType2 As HyperlinkListItemStruct
  
  If Not lParam = 0& Then
    Call RtlMoveMemory(xType1, ByVal lParam, 24&)
    If Not xType1.itemData = 0& Then
      Call RtlMoveMemory(xType2, ByVal xType1.itemData, HyperlinkListItemLen)
      xType1.itemHeight = xType2.xHeight
      Call RtlMoveMemory(ByVal lParam, xType1, 20&)
      End If
    End If
  HyperlinkList_WM_MEASUREITEM = 1&
  End Function

Public Function HyperlinkList_WM_DRAWITEM(ByVal lParam As Long) As Long
  Dim xType1 As DRAWITEMSTRUCT
  Dim xType2 As HyperlinkListItemStruct
  Dim xType3 As RECT
  Dim xLong1 As Long
  Dim xLong2 As Long
  
  If Not lParam = 0& Then
    Call RtlMoveMemory(xType1, ByVal lParam, 48&)
    If Not xType1.hdc = 0& Then
      
      xLong1 = GetBkColor(xType1.hdc)
      xLong2 = GetTextColor(xType1.hdc)
      Call SetBkColor(xType1.hdc, GetSysColor(5&)) '5&))
      Call FillRect(xType1.hdc, xType1.rcItem, 6&) '6&)

      If Not xType1.ItemID = -1& Then
        If Not xType1.itemData = 0& Then
          Call RtlMoveMemory(xType2, ByVal xType1.itemData, HyperlinkListItemLen)
          #If HyperlinkList_UseIcons Then
            If Not xType2.hIcon = 0& Then
              'If xType1.ItemID = 0& Then
              '  Call DrawIconEx(xType1.hdc, xType1.rcItem.Left + xType2.IconIdent, xType1.rcItem.Top + HyperlinkList_PaddingT, xType2.hIcon, xType2.IconSize, xType2.IconSize, 0&, 0&, 3&)
              '  Else
                Call DrawIconEx(xType1.hdc, xType1.rcItem.Left + xType2.IconIdent, xType1.rcItem.Top + xType2.Padding.Top, xType2.hIcon, xType2.IconSize, xType2.IconSize, 0&, 0&, 3&)
              '  End If
              End If
            #End If
          
          xType3 = xType1.rcItem
          xType1.rcItem.Left = xType1.rcItem.Left + xType2.Padding.Left ' HyperlinkList_PaddingL
          xType1.rcItem.Right = xType1.rcItem.Right - xType2.Padding.Right
          'If xType1.ItemID = 0& Then
          '  xType1.rcItem.Top = xType1.rcItem.Top + HyperlinkList_PaddingT
          '  xType1.rcItem.Bottom = xType1.rcItem.Bottom + HyperlinkList_PaddingT
          '  Else
            xType1.rcItem.Top = xType1.rcItem.Top + xType2.Padding.Top
            xType1.rcItem.Bottom = xType1.rcItem.Bottom + xType2.Padding.Top
          '  End If
          If Not xType2.xText = 0& Then
            If IsUnicode Then
              Call DrawTextW(xType1.hdc, xType2.xText, xType2.LenText, xType1.rcItem, &H110&)
              Else
              Call DrawTextADirect(xType1.hdc, xType2.xText, xType2.LenText, xType1.rcItem, &H110&)
              End If
            End If
          
          If xType2.LnkCapLen = 0& Then
            If (xType1.itemState And &H11&) And Not xType2.xText = 0& Then
              Call DrawFocusRect(xType1.hdc, xType3)
              End If
            Else
            'If xType1.ItemID = 0& Then
            '  xType1.rcItem.Top = xType1.rcItem.Top - HyperlinkList_PaddingT
            '  xType1.rcItem.Bottom = xType1.rcItem.Bottom - HyperlinkList_PaddingT
            '  End If
            xType1.rcItem.Right = xType1.rcItem.Left + xType2.LnkRect.Right
            xType1.rcItem.Left = xType1.rcItem.Left + xType2.LnkRect.Left
            xType1.rcItem.Bottom = xType1.rcItem.Top + xType2.LnkRect.Bottom
            xType1.rcItem.Top = xType1.rcItem.Top + xType2.LnkRect.Top
            
            If (xType1.itemState And &H11&) Then
              Call FillRect(xType1.hdc, xType1.rcItem, 14&)
              Call SetBkColor(xType1.hdc, GetSysColor(13&))
              Call SetTextColor(xType1.hdc, GetSysColor(14&))
              ElseIf IsMinWindows982000 Then
              Call SetTextColor(xType1.hdc, GetSysColor(26&)) '13&))
              Else
              Call SetTextColor(xType1.hdc, GetSysColor(13&)) '13&))
              End If
            If IsUnicode Then
              Call DrawTextW(xType1.hdc, xType2.LnkCaption, xType2.LnkCapLen, xType1.rcItem, &H110&)
              Else
              Call DrawTextADirect(xType1.hdc, xType2.LnkCaption, xType2.LnkCapLen, xType1.rcItem, &H110&)
              End If
            End If
          End If
        End If
      Call SetBkColor(xType1.hdc, xLong1)
      Call SetTextColor(xType1.hdc, xLong2)
      End If
    End If
  HyperlinkList_WM_DRAWITEM = 1&
  End Function

Public Sub HookWindow(ByVal hWnd As Long, ByVal Addr As Long)
  If Not hWnd = 0& Then Call SetWindowLong(hWnd, -21&, SetWindowLong(hWnd, -4&, Addr))
  End Sub

Public Sub UnhookWindow(ByVal hWnd As Long)
  Dim xLong1 As Long

  If Not hWnd = 0& Then
    xLong1 = GetWindowLong(hWnd, -21&)
    If Not xLong1 = 0& Then
      Call SetWindowLong(hWnd, -4&, xLong1)
      End If
    End If
  End Sub

Public Function HyperlinkList_GetURLPointerFromItem(ByVal hWnd As Long, ByVal ItemID As Long) As Long
  Dim xType1 As HyperlinkListItemStruct
  
  ItemID = SendMessageA(hWnd, &H199&, ItemID, ByVal 0&)
  If Not ItemID = 0& Then
    Call RtlMoveMemory(xType1, ByVal ItemID, HyperlinkListItemLen)
    HyperlinkList_GetURLPointerFromItem = xType1.LnkURL
    End If
  End Function

#If LoadResEx_Icon_Shared Then
Public Function OSVersionDependent(Optional ByVal MaxIconSupport As Long = 0&) As Boolean
#Else
Public Function OSVersionDependent() As Boolean
#End If
  #If XPTheme_DefControls Or LoadResEx_Icon_Shared Or DoEventsEx_Sleep Or SetIsMinWindowsXP Then
    Dim xLong1 As Long
    #End If
  #If LoadResEx_Icon_Shared Or DoEventsEx_Sleep Or SetIsMinWindowsXP Or SetIsMinWindows2000W Or SetIsMinWindows982000 Or XPTheme_DefControls Then
    Dim Major As Long
    Dim Minor As Long
    #If Unicode Then
      #Else
      Dim IsUnicode As Boolean
      #End If
    #End If

  #If LoadResEx_Icon_Shared Or DoEventsEx_Sleep Or SetIsMinWindowsXP Or SetIsMinWindows2000W Or XPTheme_DefControls Then
    xLong1 = GetVersion
    IsUnicode = ((xLong1 And &H80000000) = 0&)
    #ElseIf Unicode Then
    IsUnicode = ((GetVersion And &H80000000) = 0&)
    #End If
      
  #If LoadResEx_Icon_Shared Or DoEventsEx_Sleep Or SetIsMinWindowsXP Or SetIsMinWindows2000W Or SetIsMinWindows982000 Or XPTheme_DefControls Then
    Major = (xLong1 And &HFF&)
    Minor = (xLong1 And &HFF00&) \ &H100&
    #If SetIsMinWindowsXP Then
      IsMinWindowsXP = IsUnicode And ((Major > 5&) Or ((Major = 5&) And (Minor >= 1&)))
      #If XPTheme_DefControls Then
        If IsMinWindowsXP Then
          xLong1 = LoadLibraryA("shell32.dll")
          Call InitCommonControls
          Call FreeLibrary(xLong1)
          End If
        #End If
      #Else
      #If XPTheme_DefControls Then
        If IsUnicode And ((Major > 5&) Or ((Major = 5&) And (Minor >= 1&))) Then
          xLong1 = LoadLibraryA("shell32.dll")
          Call InitCommonControls
          Call FreeLibrary(xLong1)
          End If
        #End If
      #End If
    #If SetIsMinWindows2000W Then
      IsMinWindows2000W = IsUnicode And (Major >= 5&)
      #End If
    #If SetIsMinWindows982000 Then
      IsMinWindows982000 = (Major > 4& Or (Major = 4 And Minor >= 10))
      #End If

    #If DoEventsEx_Sleep Then
      DoEventsEx_Sleep_WaitableTimers = (IsUnicode Or (Major > 4&) Or ((Major = 4&) And (Minor >= 10&)))
      #End If
    #If LoadResEx_Icon_Shared Then
      xLong1 = GetDC(0&)
      If Not xLong1 = 0& Then
        LoadResEx_IsHighColor = (GetDeviceCaps(xLong1, 12&) > 15&)
        Call ReleaseDC(0&, xLong1)
        If MaxIconSupport > 0& Then
          xLong1 = GetVersion
          If IsUnicode Then
            'nt series; '2003=5.2=xp like icons
            'If Major > 5& Or Major = 5& And Minor > 1& Then
            If Major > 5& 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
              ElseIf Major = 5& Then
              If Minor >= 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
              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
            Else
            If Major > 4& Or Major = 4& And Minor >= 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 Major = 4& And Minor >= 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
        End If
      #End If
    #End If
  End Function

Public Function LoadCursor(ByVal CursorID As Long) As Long                                             'String) As Long
  If IsUnicode Then
    LoadCursor = LoadCursorW(0&, CursorID)
    Else
    LoadCursor = LoadCursorA(0&, CursorID)
    End If
  End Function


Private Function TxtFile_ReadOpenEx(ByVal Filename As String, ByRef InOutEncoding As Long, ByRef PureTextSize As Long, ByVal AppendAndSeekEnd As Boolean) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long

  If AppendAndSeekEnd Then
    TxtFile_ReadOpenEx = CreateFile(Filename, OpenExisting, FILE_READWRITE)
    Else
    TxtFile_ReadOpenEx = CreateFile(Filename, OpenExisting, FILE_READ)
    End If
  If Not TxtFile_ReadOpenEx = -1& Then
    PureTextSize = GetFileSize(TxtFile_ReadOpenEx, xLong1)
    If xLong1 = 0& And PureTextSize < &H4000000 Then
      If Not ReadFile(TxtFile_ReadOpenEx, ByVal VarPtr(xLong1), 3&, xLong2, 0&) = 0& Then
        'If xLong2 = 3& Or xLong2 = PureTextSize Then
'Debug.Print Hex(xLong1)
          If (xLong1 And &HFFFF&) = &HFEFF& Then
            If PureTextSize Mod 2& = 0& Then
              PureTextSize = PureTextSize - 2&
              If Not IsUnicode Then GoTo Fail
              InOutEncoding = TxtFile_EncodingEnum.CP_WINUNICODE
              If Not AppendAndSeekEnd Then
                If SetFilePointer(TxtFile_ReadOpenEx, 2&, 0&, 0&) = -1& Then GoTo Fail
                GoTo Success
                End If
              End If
            ElseIf (xLong1 And &HFFFFFF) = &HBFBBEF Then
            PureTextSize = PureTextSize - 3&
            InOutEncoding = TxtFile_EncodingEnum.CP_UTF8
            If Not IsUnicode Then GoTo Fail
            If Not AppendAndSeekEnd Then
              'If SetFilePointer(TxtFile_ReadOpenEx, 3&, 0&, 0&) = -1& Then GoTo Fail
              GoTo Success
              End If
            End If
          'End If
        End If
      If PureTextSize Mod 2& = 0& Or Not InOutEncoding = TxtFile_EncodingEnum.CP_WINUNICODE Then
        If Not SetFilePointer(TxtFile_ReadOpenEx, 0&, 0&, -2& * CLng(AppendAndSeekEnd)) = -1& Then GoTo Success
        End If
      End If
Fail:
    Call CloseHandle(TxtFile_ReadOpenEx)
    TxtFile_ReadOpenEx = 0&
    End If
Success:
  End Function

Public Function HookedWindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Dim xLong1 As Long

  #If Unicode Then
    If IsUnicode Then
      xLong1 = GetWindowLongW(hWnd, -21&)
      If Not xLong1 = 0& Then
        HookedWindowProc = CallWindowProcW(xLong1, hWnd, Msg, wParam, lParam)
        End If
      Else
      xLong1 = GetWindowLongA(hWnd, -21&)
      If Not xLong1 = 0& Then
        HookedWindowProc = CallWindowProcA(xLong1, hWnd, Msg, wParam, lParam)
        End If
      End If
    #Else
    xLong1 = GetWindowLongA(hWnd, -21&)
    If Not xLong1 = 0& Then
      HookedWindowProc = CallWindowProcA(xLong1, hWnd, Msg, wParam, lParam)
      End If
    #End If
  End Function

Public Function WordWrapText(ByVal hdc As Long, ByVal xText As String, ByVal MaxWidth As Long) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xChar1 As String
  
  If Not Len(xText) = 0& Then
    xText = Replace(Replace(Replace(xText, vbCrLf, vbCr), vbLf, vbCr), vbCr, vbCrLf) + vbCrLf
    xLong1 = InStr(xText, vbCrLf)
    xLong2 = 1&
    Do
      xChar1 = Mid(xText, xLong2, xLong1 - xLong2)
      Do
        xLong2 = GetTextExtentExPoint_FitInWidth(hdc, xChar1, MaxWidth)
        If xLong2 = Len(xChar1) Then
          WordWrapText = WordWrapText + vbCrLf + xChar1
          Exit Do
          ElseIf Mid(xChar1, xLong2 + 1&, 1&) = " " And Not Mid(xChar1, xLong2, 1&) = " " Then
          WordWrapText = WordWrapText + vbCrLf + Left(xChar1, xLong2)
          xChar1 = Mid(xChar1, xLong2 + 2&)
          Else
          xLong3 = InStrRev(xChar1, " ", xLong2)
          If xLong3 = 0& Then
            WordWrapText = WordWrapText + vbCrLf + Left(xChar1, xLong2)
            xChar1 = Mid(xChar1, xLong2 + 1&)
            Else
            WordWrapText = WordWrapText + vbCrLf + Left(xChar1, xLong3 - 1&)
            xChar1 = Mid(xChar1, xLong3 + 1&)
            End If
          End If
        Loop
      xLong2 = xLong1 + 2&
      xLong1 = InStr(xLong2, xText, vbCrLf)
      Loop Until (xLong1 = 0&)
    End If
  WordWrapText = Mid(WordWrapText, 3&)
  End Function

Public Function DrawTextGetHeight(ByVal hdc As Long, ByVal xText As String, ByVal xMode As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As RECT
  
  xType1.Right = &H1FFF&
  xType1.Bottom = &H1FFF&
  
  xLong1 = Len(xText)
  If IsUnicode Then
    Call DrawTextW(hdc, StrPtr(xText), xLong1, xType1, xMode Or &H400&)
    Else
    Call DrawTextA(hdc, xText, xLong1, xType1, xMode Or &H400&)
    End If
  DrawTextGetHeight = xType1.Bottom
  End Function

Public Function DrawTextGetWidth(ByVal hdc As Long, ByVal xText As String, ByVal xMode As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As RECT
  
  xType1.Right = &H1FFF&
  xType1.Bottom = &H1FFF&
  
  xLong1 = Len(xText)
  If IsUnicode Then
    Call DrawTextW(hdc, StrPtr(xText), xLong1, xType1, xMode Or &H400&)
    Else
    Call DrawTextA(hdc, xText, xLong1, xType1, xMode Or &H400&)
    End If
  DrawTextGetWidth = xType1.Right
  End Function

Public Function GetTextExtentExPoint_FitInWidth(ByVal hdc As Long, ByVal lpszStr As String, ByVal MaxWidth As Long) As Long
  Dim xLong1 As Long
  Dim xType1 As RECT
  
  xLong1 = Len(lpszStr)
  If IsUnicode Then
    xLong1 = GetTextExtentExPointW(hdc, StrPtr(lpszStr), xLong1, MaxWidth, GetTextExtentExPoint_FitInWidth, ByVal 0&, xType1)
    Else
    xLong1 = GetTextExtentExPointA(hdc, lpszStr, xLong1, MaxWidth, GetTextExtentExPoint_FitInWidth, ByVal 0&, xType1)
    End If
  If xLong1 = 0& Then
    GetTextExtentExPoint_FitInWidth = 0&
    End If
  End Function


