Option Explicit

Function ResetAuth (ByVal AuthPath$, ByVal AppName$) As Integer

    Dim mySB As SecureBlock
    Dim ret As Integer
    Dim Text As String

    ' clear the initial contents of the SB structure
    ClearSB mySB

    ' setup to get the installation information
    mySB.SOURCE = AuthPath$

    ' turn on the hourglass cursor
    Screen.MousePointer = 11

    ' call the EVMOV3.DLL to prepare for reset
    mySB.FUNC = 0
    ret = EVMOV3(mySB)

    ' restore the original cursor
    Screen.MousePointer = 0

    ' verify the success of the EVMOVE function
    If ret <> 0 Then

        ' show the user the error
        MsgBox "EVMOV3.DLL Error " + Str$(ret) + "!", 16, AppName$

        ' set the error code return from this function
        ResetAuth = ret

        ' abort the reset processing
        Exit Function

    ElseIf mySB.STAT1 <> 0 Then

        ' show the user the error
        MsgBox "Security Error: " + FormatError$(mySB), 16, AppName$

        ' set the error code return from this function
        ResetAuth = mySB.STAT1

        ' abort the reset processing
        Exit Function
    End If

    ' load the registration information form
    Load ResetInfoDlg

    ' set the inital value of the dialog's controls
    ResetInfoDlg.Caption = AppName$
    ResetInfoDlg.lblSerialNumber = Trim$(Str$(mySB.SNP)) + "-" + Trim$(Str$(mySB.RUC))
    ResetInfoDlg.lblDate = mySB.CDATE
    ResetInfoDlg.txtResetCode.Text = ""
    
    
    ' display the form to get the reset information
    ResetInfoDlg.Show 1

    ' get the results of the dialog box
    ret = Val(ResetInfoDlg.Tag)
    mySB.CODE = ResetInfoDlg.txtResetCode.Text

    ' remove the reset information dialog from memory
    Unload ResetInfoDlg

    ' if the user selected cancel abort the move
    If ret <> 0 Then

        ' set the return code for this function
        ResetAuth = 2

        ' abort the move processing
        Exit Function
    End If

    ' turn on the hourglass cursor
    Screen.MousePointer = 11

    ' actually perform the reset of the copy-protection
    mySB.FUNC = 2
    ret = EVMOV3(mySB)

    ' restore the original cursor
    Screen.MousePointer = 0

    ' verify the success of the EVMOVE function
    If ret <> 0 Then

        ' show the user the error
        MsgBox "EVMOV3.DLL Error " + Str$(ret) + "!", 16, AppName$

        ' set the error code return from this function
        ResetAuth = ret

        ' abort the reset processing
        Exit Function

    ElseIf mySB.STAT1 <> 0 Then

        ' show the user the error
        MsgBox "Security Error: " + FormatError$(mySB), 16, AppName$

        ' set the error code return from this function
        ResetAuth = mySB.STAT1

        ' abort the reset processing
        Exit Function
    End If

    ' if we end up here then the reset was successfull
    ResetAuth = 0

End Function

