[API]
EnableWindow
GetDlgItem

[INCLUDE]
LenLongToChar
SetDlgItemText
TxtFile_ReadComplete

[DEFINE]
Public AbortRegConvert As Boolean

[CODE]
Public Function ConvertRegestryA_ReadFile(ByVal ExeFileName As String, ByRef IsV5 As Boolean, Optional ByVal FileID As Long = -1&) As String
  Dim xChar1 As String
  Dim xLong1 As Long
  Dim xBool1 As Boolean

  If FileID = -1& Or FileID = 0& Then FileID = FreeFile

  If Left(ExeFileName, 1&) & Right(ExeFileName, 1&) = Chr(34&) & Chr(34&) And Not Len(ExeFileName) = 1& Then
    ExeFileName = Mid(ExeFileName, 2&, Len(ExeFileName) - 2&)
    End If

  If ReadCompleteTxtFile(ExeFileName, ConvertRegestryA_ReadFile) Then
    DoEvents
    xLong1 = InStr(ConvertRegestryA_ReadFile, vbCr)
    If xLong1 = 0& Then
      ConvertRegestryA_ReadFile = Chr(1&)
      Else
      xChar1 = UCase(Trim(Left(ConvertRegestryA_ReadFile, xLong1 - 1&)))
      'ConvertRegestryA_ReadFile = Mid(ConvertRegestryA_ReadFile, xLong1 + 1&) & vbCr
      If Left(xChar1, 8&) = "REGEDIT4" Then
        xBool1 = True
        IsV5 = False
        ElseIf Left(xChar1, 36&) = "WINDOWS REGISTRY EDITOR VERSION 5.00" Then
        xBool1 = True
        IsV5 = True
        End If
      If xBool1 And UCase(Right(ExeFileName, 4&)) = ".REG" Then
        'ConvertRegestryA_ReadFile = Replace(Replace(Mid(ConvertRegestryA_ReadFile, xLong1 + 1&) & vbCr, vbLf, ""), vbTab, "")
        ConvertRegestryA_ReadFile = Replace(ConvertRegestryA_ReadFile, vbTab, "")
        DoEvents
        If Trim(Replace(ConvertRegestryA_ReadFile, vbCrLf, "")) = "" Then
          ConvertRegestryA_ReadFile = Chr(1&) '"" ' vbNullChar
          'Else
          'SuccessFull
          End If
        DoEvents
        Else
        ConvertRegestryA_ReadFile = ""
        End If
      End If
    Else
    ConvertRegestryA_ReadFile = Chr(2&)
    End If
  End Function

Public Function ConvertRegestryA(ByRef RegestryData As String, ByRef LogData As String, ByRef IsV5 As Boolean, Optional ByVal ProgressControl As Long = 0&, Optional ByVal ProgressStart As Long = 0&, Optional ByVal ProgressTotal As Long = 0&, Optional ByVal ProgressQueue As Long = 0&, Optional hWndDialog As Long, Optional StaticID As Long, Optional ByVal StaticText As String, Optional ByVal EnableButtonID As Long) As Long
  Dim xCharA1() As String
  Dim xCharA2() As String
  Dim xLong1 As Long 'LineCounter
  'Dim xLong2 As Long 'ExeDataStartPos
  Dim xLong3 As Long 'TotalLines
  Dim xLong4 As Long
  Dim xLong5 As Long
  Dim xBool1 As Long
  Dim xChar1 As String
  Dim xChar2 As String
  Dim xChar3 As String
  Dim xChar4 As String
  Dim xCurrentKey As String
  Dim xKeyOpen As Long
  Dim xCurrentKeyID As Long
  Dim xLong2 As Long ' OutCounter
  Dim MustExpandStrings As Boolean

  xCharA1() = Split(RegestryData, vbCrLf)
  DoEvents
  xLong3 = UBound(xCharA1())
  RegestryData = ""
  ReDim xCharA2(xLong3)

  If Not StaticID = 0& Then
    Call SetDlgItemText(hWndDialog, StaticID, StaticText)
    End If
  If Not EnableButtonID = 0& Then
    Call EnableWindow(GetDlgItem(hWndDialog, EnableButtonID), 1&)
    End If

  AbortRegConvert = False
  xLong1 = 1&
  Do Until (AbortRegConvert Or xLong1 = xLong3 + 1&)
    xChar1 = Trim(xCharA1(xLong1))
    'If (xLong1 Mod 64&) = 0& Then
      'ctProgressA1_ValueSet xLong1 / xLong3, Replace(LoadResEx_String(121), "$", Trim(Str(CInt(xLong1 * 100& / xLong3)))): DoEvents
    'Call ConvertRegestryA_Callback(xLong1, xLong3)
    ctProgressB_SetValue ProgressControl, ProgressStart + xLong1 / xLong3 * ProgressQueue, ProgressTotal
    xLong1 = xLong1 + 1&
    Select Case Left(xChar1, 2&)
      Case "[-"
        xCurrentKey = Mid(xChar1, 3&)
        xCurrentKeyID = RegToExe_GetCurrentKey(xCurrentKey)
        xKeyOpen = 3&
        xBool1 = RegToExe_IsStrReallyUnicode(xCurrentKey)
        xChar2 = LenLongToChar(xCurrentKeyID + &H3000000 + RegToExe_IsW(xBool1)) & RegToExe_chrX(Len(xCurrentKey)) & RegToExe_MakeW(xCurrentKey, xBool1)
      Case "[*" ' delete subkeys
        xCurrentKey = Mid(xChar1, 3&)
        xCurrentKeyID = RegToExe_GetCurrentKey(xCurrentKey)
        xKeyOpen = 1&
        xBool1 = RegToExe_IsStrReallyUnicode(xCurrentKey)
        xChar2 = LenLongToChar(xCurrentKeyID + &H4000000 + RegToExe_IsW(xBool1)) & RegToExe_chrX(Len(xCurrentKey)) & RegToExe_MakeW(xCurrentKey, xBool1)
      Case "[?" ' deletevalues
        xCurrentKey = Mid(xChar1, 3&)
        xCurrentKeyID = RegToExe_GetCurrentKey(xCurrentKey)
        xKeyOpen = 1&
        xBool1 = RegToExe_IsStrReallyUnicode(xCurrentKey)
        xChar2 = LenLongToChar(xCurrentKeyID + &H5000000 + RegToExe_IsW(xBool1)) & RegToExe_chrX(Len(xCurrentKey)) & RegToExe_MakeW(xCurrentKey, xBool1)
      Case "[&"
        xCurrentKey = Mid(xChar1, 3&)
        xCurrentKeyID = RegToExe_GetCurrentKey(xCurrentKey)
        xKeyOpen = 1&
        xBool1 = RegToExe_IsStrReallyUnicode(xCurrentKey)
        xChar2 = LenLongToChar(xCurrentKeyID + &H2000000 + RegToExe_IsW(xBool1)) & RegToExe_chrX(Len(xCurrentKey)) & RegToExe_MakeW(xCurrentKey, xBool1)
        'xcurrentkey:
        ' -1 -> not currently used
        ' -2 -> error getting name -> -1&
      Case Else
      Select Case Trim(Left(xChar1, 1&))
        Case "["
          xCurrentKey = Mid(xChar1, 2&)
          xKeyOpen = 1&
          xCurrentKeyID = RegToExe_GetCurrentKey(xCurrentKey)
          xBool1 = RegToExe_IsStrReallyUnicode(xCurrentKey)
          xChar2 = LenLongToChar(xCurrentKeyID + &H1000000 + RegToExe_IsW(xBool1)) & RegToExe_chrX(Len(xCurrentKey)) & RegToExe_MakeW(xCurrentKey, xBool1)
        Case ";"
        Case ""
        Case Else
        If xKeyOpen = 0& Then ' xCurrentKey = "" Then
          xChar2 = vbNullChar
          Else
          xChar2 = xChar1 'preserve xchar1 for logfile / error reporting
          xLong4 = RegToExe_GetParams(xChar2, xChar3, xCharA1(), xLong1, xLong3, MustExpandStrings)
          If xLong4 = -1& Then
            xChar2 = vbNullChar
            ElseIf xLong4 = 0 Then
'            Stop
            
            xBool1 = RegToExe_IsStrReallyUnicode(xChar2)
            xChar2 = LenLongToChar(RegToExe_IsW(xBool1)) + RegToExe_chrX(Len(xChar2)) & RegToExe_MakeW(xChar2, xBool1)
'            Stop
            Else
            'xChar2 = xChar2 & vbNullChar & xChar3
            xBool1 = RegToExe_IsStrReallyUnicode(xChar2)
'            Stop
            Select Case xLong4
              Case 1&, 2&, 7& 'REGTYPE_MULTI_SZ, REGTYPE_EXPAND_SZ
                If MustExpandStrings Then
                  xLong5 = Len(xChar3)
                  If IsV5 And Not xLong5 = 0& Then
                    xChar4 = String((xLong5 + 1&) / 2&, vbNullChar)
                    Call RtlMoveMemory(ByVal StrPtr(xChar4), ByVal xChar3, xLong5)
                    xChar3 = xChar4
                    End If
                  End If
'Public Const REG_SZ = 1                         ' Unicode nul terminated string
'Public Const REG_EXPAND_SZ = 2                  ' Unicode nul terminated string
'Public Const REG_MULTI_SZ = 7                   ' Multiple Unicode strings
  '              Stop
                xChar4 = RegToExe_LowerCaseSpecial(xChar3)
                xLong5 = RegToExe_IsStrReallyUnicode(xChar4)
                'If RegToExe_IsStrReallyUnicode(xChar4) Then
                If xLong5 Then
'                  Stop
                  xBool1 = xBool1 + &H40000000
                  xChar4 = RegToExe_MakeW(xChar4, xLong5)
                  End If
'                Stop
              Case Else
                If xLong4 = 4 Then
                  If Not Len(xChar3) = 4 Then
'                    Stop
                    xChar2 = vbNullChar
                    GoTo NoDo
                    End If
                  End If
                xChar4 = RegToExe_LowerCaseSpecial(xChar3)
                'xChar3 = RegToExe_MakeW(xChar3)
                'xChar3 = RegToExe_LowerCaseSpecial(xChar3)
                'xChar3 = MakeA(xChar3)
'                Stop
              End Select
'            Stop
            xChar2 = LenLongToChar(xLong4 + RegToExe_IsW(xBool1 And &H80000001) + (xBool1 And &H40000000)) + RegToExe_chrX(Len(xChar2)) & RegToExe_MakeW(xChar2, (xBool1 And &H80000001)) & LenLongToChar(Len(xChar3)) & xChar4
NoDo:
            End If
          End If
        End Select
      End Select
    
    
    
    If xCurrentKeyID = -1& Or xChar2 = vbNullChar Then
      If xCurrentKeyID = -1& Then
        xCurrentKey = ""
        xKeyOpen = 0&
        xCurrentKeyID = 0&
        End If
      LogData = LogData & vbCrLf & Replace(LoadResEx_String(130), "$", Trim(Str(xLong1 + 1&))) & " " & xChar1
      xChar2 = ""
      ElseIf Not xChar2 = "" Then
      If xKeyOpen = 3& Then
        xKeyOpen = 2&
        ElseIf xKeyOpen = 2& Then
        xKeyOpen = 1&
        'RegestryData = RegestryData & Chr(xCurrentKeyID + &H80&) & RegToExe_chrX(Len(xCurrentKey)) & xCurrentKey
        xBool1 = RegToExe_IsStrReallyUnicode(xCurrentKey)
        xCharA2(xLong2) = LenLongToChar(xCurrentKeyID + &H1000000 + xBool1) & RegToExe_chrX(Len(xCurrentKey)) & RegToExe_MakeW(xCurrentKey, xBool1)
        xLong2 = xLong2 + 1&
        End If
      'RegestryData = RegestryData & xChar2
      xCharA2(xLong2) = xChar2
      xLong2 = xLong2 + 1&
      xChar2 = ""
      End If
    Loop
  LogData = Mid(LogData, 3&)
'  Stop
  If Not xLong2 = 0& Then
    'Stop
    If AbortRegConvert Then
      RegestryData = vbNullChar
      Else
      ReDim Preserve xCharA2(xLong2 - 1&)
      RegestryData = Join(xCharA2(), "")
      DoEvents
      End If
    ConvertRegestryA = Len(LogData)
    End If
  End Function

Private Function RegToExe_GetCurrentKey(ByRef CompleteKey As String) As Long
  Static xLong1 As Long
  
  CompleteKey = Trim(CompleteKey)
  If Right(CompleteKey, 1&) = "]" Then
    CompleteKey = Left(CompleteKey, Len(CompleteKey) - 1&)
    xLong1 = InStr(CompleteKey & "\", "\") - 1&
    Select Case UCase(Left(CompleteKey, xLong1))
      Case "HKEY_CLASSES_ROOT": RegToExe_GetCurrentKey = &H0&
      Case "HKEY_CURRENT_USER": RegToExe_GetCurrentKey = &H1&
      Case "HKEY_LOCAL_MACHINE": RegToExe_GetCurrentKey = &H2&
      Case "HKEY_USERS": RegToExe_GetCurrentKey = &H3&
      Case "HKEY_PERFORMANCE_DATA": RegToExe_GetCurrentKey = &H4&
      Case "HKEY_CURRENT_CONFIG": RegToExe_GetCurrentKey = &H5&
      Case "HKEY_DYN_DATA": RegToExe_GetCurrentKey = &H6&
      Case Else
        RegToExe_GetCurrentKey = -1&
      End Select
    Else
    RegToExe_GetCurrentKey = -1&
    End If
  CompleteKey = Mid(CompleteKey, xLong1 + 2&)
  End Function

Private Function RegToExe_chrX(ByVal xLong1 As Long) As String
  RegToExe_chrX = Chr(xLong1 And &HFF&) + Chr(xLong1 \ &H100&)
  End Function

' This is now isolated, xdata/counter byref if hex ... \ is userd to process
' Also need to update processbar here, so xtotal is passed too ... byref! but not overwritten
Private Function RegToExe_GetParams(ByRef xName As String, ByRef xData As String, ByRef xArray() As String, ByRef xCounter As Long, ByRef xTotal As Long, ByRef MustExpandStrings As Boolean) As Long ', ByRef ProgressStart As Long, ByRef ProgressTotal As Long, ByRef ProgressQueue As Long) As Long
  'returns multiplier or -1
  
  Static xLong1 As Long
  Static xChar1 As String

  MustExpandStrings = False

  ' This should now make it real "..."="..." or @=... compatible
  ' When finished, on each side chr(0) has to be replaced with "
  ' \\ is also fixed here to \
  'xData = LTrim(Replace(Replace(xName, "\" & Chr(34), vbNullChar), "\\", "\"))
  xData = LTrim(Replace(Replace(Replace(xName, "\\", Chr(1&)), "\" & Chr(34), vbNullChar), Chr(1&), "\"))
  
  If Left(xData, 2&) = "@=" Then
    xName = ""
    xData = LTrim(Mid(xData, 2&))
    ElseIf Left(xData, 1&) = Chr(34&) Then
    RegToExe_GetParams = InStr(2&, xData, Chr(34&))
    If RegToExe_GetParams = 0& Then
      RegToExe_GetParams = -1&
      Else
      xName = Mid(xData, 2&, RegToExe_GetParams - 2&)
      xData = LTrim(Mid(xData, RegToExe_GetParams + 1&))
      End If
    Else
    RegToExe_GetParams = -1&
    End If
  
  If Not RegToExe_GetParams = -1& Then
    If Left(xData, 1&) = "=" Then
      xData = LTrim(Mid(xData, 2&))
      xChar1 = LCase(xData)
      If Left(xData, 1&) = Chr(34) Then
        RegToExe_GetParams = InStr(2&, xData, Chr(34&))
        If RegToExe_GetParams = 0& Then
          RegToExe_GetParams = -1&
          Else
          If LTrim(Mid(xData, RegToExe_GetParams + 1&)) = "" Then
            xData = Replace(Mid(xData, 2&, RegToExe_GetParams - 2&), vbNullChar, Chr(34&))
            RegToExe_GetParams = 1&
            Else
            RegToExe_GetParams = -1&
            End If
          End If
        ElseIf Left(xChar1, 6&) = "dword:" Then
        xData = Mid(xData, 7&)
        RegToExe_GetParams = RegToExe_ValidDWord(xData)
        ' Using external function
        ElseIf Left(xChar1, 3&) = "hex" Then
          ' here both hex(): and hex: because both may use ...\ multilines
        Select Case Left(xChar1, 4&)
          Case "hex:"
            RegToExe_GetParams = 3&
'            Stop
            xChar1 = LTrim(Mid(xData, 5&))
          Case "hex("
            xData = LTrim(Mid(xData, 5&))
            MustExpandStrings = True
            xLong1 = InStr(xData, ")")
            If xLong1 = 0& Then
              RegToExe_GetParams = -1&
              Else
              xChar1 = Trim(Left(xData, xLong1 - 1&))
              RegToExe_GetParams = RegToExe_AntHex(xChar1)
              If Not RegToExe_GetParams = -1& Then
                If Hex(RegToExe_GetParams) = UCase(xChar1) Then
                  xData = LTrim(Mid(xData, xLong1 + 1&))
                  If Left(xData, 1&) = ":" Then
                    xChar1 = Mid(xData, 2&)
                    'xName = RegToExe_chrX(RegToExe_GetParams) & Replace(xName, vbNullChar, Chr(34&))
                    xName = Replace(xName, vbNullChar, Chr(34&))
                    'RegToExe_GetParams = 2&
                    Else
                    RegToExe_GetParams = -1&
                    End If
                  Else
                  RegToExe_GetParams = -1&
                  End If
                End If
              End If
          Case Else
            RegToExe_GetParams = -1&
          End Select
          
        If Not RegToExe_GetParams = -1& Then
          'xData = ","
          xData = ""
          Do
            xChar1 = RTrim(xChar1)
            If Right(xChar1, 2&) = ",\" Then
              If xCounter = xTotal Then
                RegToExe_GetParams = -1&
                Exit Do
                Else
                xChar1 = Left(xChar1, Len(xChar1) - 2&)
                If RegToExe_ValidHex(xData, xChar1) Then
                  '''xData = xData & RTrim(Left(xChar1, Len(xChar1) - 1&))
                  xChar1 = LTrim(xArray(xCounter))
                  'If (xCounter And 16&) = 0& Then ctProgressA1_ValueSet xCounter / xTotal, Replace(LoadResEx_String(121), "$", Trim(Str(CInt(xCounter * 100& / xTotal)))): DoEvents
                  'ctProgressB_SetValue ProgressControl, ProgressStart + xCounter / Total * ProgressQueue, ProgressTotal
                  xCounter = xCounter + 1&
                  Else
                  RegToExe_GetParams = -1&
                  Exit Do
                  End If
                End If
              Else
              If Not RegToExe_ValidHex(xData, xChar1) Then
                RegToExe_GetParams = -1&
                End If
'              Stop
              Exit Do
              End If
            Loop
          'If Not RegToExe_GetParams = -1& Then
          '  xData = Mid(xData, 2&)
          '  End If
          End If
        
        ElseIf RTrim(xData) = "-" Then
        xData = ""
        RegToExe_GetParams = 0&
        ElseIf xName = "" And xData = "" Then
        xData = ""
        RegToExe_GetParams = 0&
        Else
        RegToExe_GetParams = -1&
        End If
      Else
      RegToExe_GetParams = -1&
      End If
    End If
          
  If Not (RegToExe_GetParams = -1& Or RegToExe_GetParams = 2&) Then
    xName = Replace(xName, vbNullChar, Chr(34&))
    End If
  End Function

Private Function RegToExe_ValidDWord(ByRef xChar1 As String) As Long
  Static xLong1 As Long
  Static xLong2 As Long
  Static xLong3 As Long
  Dim xChar2 As String

  RegToExe_ValidDWord = 4&
  If Len(xChar1) = 8& Then
    For xLong1 = 7& To 1& Step -2&
      xLong2 = RegToExe_GetHexValueByte(Mid(xChar1, xLong1, 1&))
      xLong3 = RegToExe_GetHexValueByte(Mid(xChar1, xLong1 + 1&, 1&))
      If xLong2 = -1& Or xLong3 = -1& Then
        RegToExe_ValidDWord = -1&
        Exit For
        Else
        xChar2 = xChar2 + Chr(16& * xLong2 + xLong3)
        End If
      Next
    xChar1 = xChar2
    Else
    RegToExe_ValidDWord = -1&
    End If
  End Function

Private Function RegToExe_ValidHex(ByRef HexOld As String, ByVal HexNew As String) As Boolean
Static xLong1 As Long
Static xLong2 As Long
Static xLong3 As Long
Dim xChar1 As String

HexNew = "," & Replace(Replace(Replace(HexNew, " ", ""), ",,", ",00,"), ",,", ",00,")
xLong1 = Len(HexNew)
xLong2 = xLong1 \ 3&

RegToExe_ValidHex = True
If (xLong2) * 3& = xLong1 Then
  For xLong1 = 0& To xLong2 - 1&
    xLong3 = xLong1 * 3& + 1&
    If Mid(HexNew, xLong3, 1&) = "," Then
      xLong2 = RegToExe_GetHexValueByte(Mid(HexNew, xLong3 + 1&, 1&))
      xLong3 = RegToExe_GetHexValueByte(Mid(HexNew, xLong3 + 2&, 2&))
      If xLong2 = -1& Or xLong3 = -1& Then
        RegToExe_ValidHex = False
        Exit For
        Else
        xChar1 = xChar1 & Chr(xLong2 * 16& + xLong3)
        End If
      Else
      RegToExe_ValidHex = False
      Exit For
      End If
    Next
  ElseIf Not xLong1 = 1& Then
  RegToExe_ValidHex = False
  End If

If RegToExe_ValidHex Then
  HexOld = HexOld & xChar1
  End If
End Function

Private Function RegToExe_AntHex(ByVal xChar1 As String) As Long
Static xLong1 As Long
Static xLong2 As Long
Static xLong3 As Long

xLong2 = Len(xChar1) - 1&

For xLong1 = 0& To xLong2
  xLong3 = RegToExe_GetHexValueByte(Mid(xChar1, xLong1 + 1&, 1&))
  If xLong3 = -1& Then
    RegToExe_AntHex = -1&
    Exit For
    Else
    RegToExe_AntHex = RegToExe_AntHex + (16& ^ (xLong2 - xLong1)) * xLong3
    End If
  Next
End Function

Private Function RegToExe_GetHexValueByte(ByVal xChar1 As String) As Long
RegToExe_GetHexValueByte = InStr("0123456789ABCDEF", UCase(Left(xChar1, 1&))) - 1&
End Function



      'ctProgressA1_ValueSet xLong1 / xLong3, Replace(LoadResEx_String(121), "$", Trim(Str(CInt(xLong1 * 100& / xLong3)))): DoEvents


Private Function RegToExe_MakeW(ByVal xChar1 As String, ByVal ReallyConvert As Long) As String
  Dim xLong1 As Long
  
  'if not reallyconvert=&h80000000
  'ReallyConvert = 1&
  If ReallyConvert = 1& Then
'    Stop
 '   Debug.Print "String: ConvertW"
    RegToExe_MakeW = StrConv(xChar1, vbUnicode)
    ElseIf ReallyConvert Then
'If Not ReallyConvert = -1& Then Stop
  '  Debug.Print "String: CopyToW"
    xLong1 = Len(xChar1)
    RegToExe_MakeW = String(xLong1 * 2&, vbNullChar)
    Call RtlMoveMemory(ByVal RegToExe_MakeW, ByVal StrPtr(xChar1), xLong1 * 2&)
    Else
   ' Debug.Print "String: KeepAsc"
    RegToExe_MakeW = xChar1
    End If
  End Function

Private Function RegToExe_LowerCaseSpecial(ByVal xChar1 As String) As String
  xChar1 = RegToExe_ReplaceDual(xChar1, "path")
  xChar1 = RegToExe_ReplaceDual(xChar1, "winpath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "syspath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "temppath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "progspath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "progscommonpath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "appdatapath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "localappdatapath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "commonappdatapath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "templatespath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "commontemplatespath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "profilespath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "desktoppath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "mydocspath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "mypicturespath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "mymusicpath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "myvideospath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "commondesktoppath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "commondocspath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "commonpicturespath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "commonmusicpath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "commonvideospath")
  xChar1 = RegToExe_ReplaceDual(xChar1, "username")
  RegToExe_LowerCaseSpecial = RegToExe_ReplaceDual(xChar1, "computername")
  End Function

Private Function RegToExe_ReplaceDual(ByVal xChar1 As String, ByVal xChar2 As String) As String
  xChar2 = "<reg2exe" + xChar2 + ">"
  xChar1 = Replace(xChar1, xChar2, xChar2, , , vbTextCompare)
  xChar2 = RegToExe_MakeW(xChar2, &HFFFFFFFF)
  RegToExe_ReplaceDual = Replace(xChar1, xChar2, xChar2, , , vbTextCompare)
  End Function

Private Function RegToExe_IsStrReallyUnicode(ByVal xChar1 As String) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar2 As String
  
#If 0 Then
  Dim xChar3 As String

'  Stop
  xChar2 = StrConv(xChar1, vbUnicode)
  xLong1 = Len(xChar1)
  xChar3 = String(xLong1, vbNullChar)
  Call RtlMoveMemory(ByVal StrPtr(xChar3), ByVal xChar2, xLong1 * 2)
'  Stop
  
'  If Left(xChar1, 2) = "aa" Then Stop
  
  If xChar3 = xChar1 Then
    For xLong1 = 1& To Len(xChar1)
      If Asc(Mid(xChar1, 1&)) > 126& Then
        RegToExe_IsStrReallyUnicode = 1&
        Exit For
        End If
      Next
    Else
    RegToExe_IsStrReallyUnicode = &H80000000
    End If
  
#Else
  xChar2 = RegToExe_MakeW(xChar1, &HFFFFFFFF)
  
'Stop
'If InStr(xChar1, "ä") Then Stop
  
  For xLong1 = 1 To Len(xChar1)
    xLong2 = Asc(Mid(xChar1, xLong1, 1))
    If Not (xLong2 = AscW(Mid(xChar2, xLong1 * 2 - 1&, 1)) And AscW(Mid(xChar2, xLong1 * 2, 1)) = 0&) Or xLong2 > 255& Then
'      Stop
      RegToExe_IsStrReallyUnicode = &H80000000
      Exit For
      ElseIf xLong2 > 126& Then
'Stop
      RegToExe_IsStrReallyUnicode = 1&
'      Exit For
      End If
    Next
#End If
'Stop
'  Debug.Print "String: " + xChar1 + ", result: "; RegToExe_IsStrReallyUnicode
  End Function

Private Function RegToExe_IsW(ByVal xLong1) As Long
  If xLong1 Then
    RegToExe_IsW = &H80000000
    End If
  End Function
